# tradeByTargetAmount()

{% hint style="info" %}
The function parameters must include the list of orders (tradeActions) to interact with.&#x20;

**Using the SDK is highly recommended.** See [Performing Trades](https://docs.carbondefi.xyz/developer-guides/carbon-defi-sdk/interacting-with-the-sdk/performing-trades) for details.&#x20;
{% endhint %}

### Function **tradeByTargetAmount()**

This function will trade to receive the exact amount of indicated **target** tokens for as few **source** tokens as possible.&#x20;

{% code title="CarbonController.sol" overflow="wrap" lineNumbers="true" %}

```solidity
    function tradeByTargetAmount(
        Token sourceToken,
        Token targetToken,
        TradeAction[] calldata tradeActions,
        uint256 deadline,
        uint128 maxInput
    ) external payable nonReentrant whenNotPaused onlyProxyDelegate returns (uint128)
```

{% endcode %}

### **Function Arguments**

<table><thead><tr><th width="196">Name</th><th width="147.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td>sourceToken</td><td>Token</td><td>The source token address</td></tr><tr><td>targetToken</td><td>Token</td><td>The target token address</td></tr><tr><td>tradeActions</td><td>list</td><td>This is a list of TradeAction objects, each of which  contain the <strong>strategyId</strong> and <strong>amount</strong> of target tokens to <strong>receive</strong> from the strategy. </td></tr><tr><td>deadline</td><td>uint256</td><td>Unix timestamp after which the transaction will revert</td></tr><tr><td>maxInput</td><td>uint128</td><td>The maximum amount of source tokens you are willing to spend (use) for the transaction to result in the requested targetToken amount and not revert</td></tr></tbody></table>

{% hint style="warning" %}
tradeAction `amount` need to follow the relevant token decimal. \
tradeByTargetAmount, follows the targetToken decimals
{% endhint %}

### Example

{% code overflow="wrap" %}

```solidity
tradeByTargetAmount(
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, //source token
0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C, //target token
[{59, 1600000000000000000}, {72, 3140000000000000000}], //array of tradeActions [{strategyId, amount},{strategyId, amount}...]
1675680190, //deadline
5320000000000000000 //maxInput
)
```

{% endcode %}

{% hint style="success" %}
While all required data is available on chain, it is recommended to use the [Carbon DeFi SDK](https://docs.carbondefi.xyz/developer-guides/carbon-defi-sdk).
{% endhint %}

{% hint style="info" %}
To trade directly with the ETH token, use the contract address: *0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE*&#x20;
{% endhint %}
