# TransferTokens

## Description

This function can transfer native currencies and tokens that follow the ERC-20 standard. It is recommended to first call the [`EstimateTransferTokensGas`](/js-sdk/sdk-reference/estimatetransfertokensgas.md) function to get an estimate of the gas fees required for this transaction, which can be displayed to users before the confirm or deny the transaction.

This function should be called after the [`Login`](/js-sdk/sdk-reference/login.md) has been invoked.

## Details

### Signature

`async TransferTokens(args, apiKey)`

### Arguments

<table><thead><tr><th width="258">Parameter</th><th width="114">Type</th><th>Definition</th></tr></thead><tbody><tr><td><code>args.callback</code></td><td>Function</td><td><p>Function to callback upon success or failed transfer. <br>Structure of result object passed into callback function:</p><pre class="language-json" data-line-numbers><code class="lang-json"><strong>{
</strong><strong>    "status": "1/0", // "SUCCESS"/"FAILED"
</strong><strong>    "data": "data", // the transaction object
</strong><strong>    "error": "error", // error if any
</strong><strong>}
</strong></code></pre></td></tr><tr><td><code>args.to</code></td><td>String</td><td>Address to send tokens to.</td></tr><tr><td><code>args.amount</code></td><td>String</td><td>Amount to send in <strong>display units</strong> of the currency. So if you want the user to pay 0.5 ETH, pass in '0.5' to this field. </td></tr><tr><td><code>args.currency</code></td><td>Asset (class)</td><td>Asset object of the currency you want to send. You can pass a custom token here as well, please refer to the example below.</td></tr><tr><td><code>apiKey</code></td><td>String</td><td>The API Key generated from the <a href="https://developer-test.usemeta.fi/">Developer Portal</a></td></tr></tbody></table>

### Return Value

None

## Example

Calling TransferTokens for a native currency:

{% code lineNumbers="true" %}

```jsx
import { TransferTokens } from '@metafi/metafi-js-package';

function App() {
    const transferNative = () => {
        TransferTokens({
                to: "0xd4594dECd0ed8BA4C7d5810dbB8D004C74250BD5",
                amount: "1",
                currency: assets.matic_matic,
                callback: (result) => {
                    console.log("callback result", result);
                },
            },
            "YOUR-API-KEY"
        );
    }
    
    return (
        <div>
	    <button onClick={transferNative}>Transfer 1 Matic</button>
        </div>
    );
}

export default App;

```

{% endcode %}

Calling TransferTokens for an ERC-20 token. For more information on the [`RegisterToken`](/js-sdk/sdk-reference/registertoken.md) function, please refer to this page.

{% code lineNumbers="true" %}

```jsx
import { 
    TransferTokens,
    RegisterToken,
} from '@metafi/metafi-js-package';

function App() {
    
    var customERC20Token = RegisterToken(
        "Custom Token", // name of the token
        "customToken", // symbol of the token
	chains.matic, // chain of the token
	"https://d2qdyxy3mxzsfv.cloudfront.net/images/logo/token.png", // icon image for the token
        "0x2d7882bedcbfddce29ba99965dd3cdf7fcb10a1e", // contract address for the token contract
        18, // decimals for the token
        { 
            name: "erc20",
	} // token standard
    );

    const transferErc20 = () => {
        TransferTokens({
                to: "0xd4594dECd0ed8BA4C7d5810dbB8D004C74250BD5",
                amount: "1",
                currency: customERC20Token, // use your custom token object here
                callback: (result) => {
                    console.log("callback result", result);
                },
            },
            "YOUR-API-KEY"
        );
    }
    
    return (
        <div>
	    <button onClick={transferErc20}>Transfer 1 Matic</button>
        </div>
    );
}

export default App;

```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.usemeta.fi/js-sdk/sdk-reference/transfertokens.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
