# tradeBySourceAmount()

{% 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 **tradeBySourceAmount()**

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

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

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

{% endcode %}

### **Function Arguments**

<table><thead><tr><th width="196">Name</th><th width="168.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td>sourceToken</td><td>Token address</td><td>The source token address</td></tr><tr><td>targetToken</td><td>Token address</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 source tokens to trade into the strategy</td></tr><tr><td>deadline</td><td>uint256</td><td>Unix timestamp after which the transaction will revert</td></tr><tr><td>minReturn</td><td>uint128</td><td>The minimum amount of target tokens that must be received for the transaction to not revert</td></tr></tbody></table>

{% hint style="warning" %}
tradeAction`amount`needs to follow the relevant token decimal. \
tradeBySourceAmount, follows the sourceToken decimals
{% endhint %}

### Example

{% code overflow="wrap" %}

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

{% 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 %}
