# tradeByTargetAmount()

### Function **tradeByTargetAmount()**

```solidity
    function tradeByTargetAmount(
        Token sourceToken,
        Token targetToken,
        uint256 targetAmount,
        uint256 maxSourceAmount,
        uint256 deadline,
        address beneficiary
    ) external payable 
```

Trades to receive the exact amount of **target** tokens for as few **source** tokens as possible.&#x20;

### **Function Arguments**

| Name            | Type    | Description                                                                            |
| --------------- | ------- | -------------------------------------------------------------------------------------- |
| sourceToken     | Token   | The source token address                                                               |
| targetToken     | Token   | The target token address                                                               |
| targetAmount    | uint256 | The exact amount of tokens to receive                                                  |
| maxSourceAmount | uint256 | The maximum amount of source tokens that can be used for the transaction to not revert |
| deadline        | uint256 | Unix timestamp after which the transaction will revert                                 |
| beneficiary     | address | The address receiving the target tokens                                                |

See [Errors and Troubleshooting](https://docs.bancor.network/developer-guides/write-functions/trading/trading-troubleshooting) for a list of common errors and how to resolve them.&#x20;

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