TransferTokens

Description

This function can transfer native currencies and tokens that follow the ERC-20 standard. It is recommended to first call the EstimateTransferTokensGas 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 has been invoked.

Details

Signature

async TransferTokens(args, apiKey)

Arguments

Return Value

None

Example

Calling TransferTokens for a native currency:

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;

Calling TransferTokens for an ERC-20 token. For more information on the RegisterToken function, please refer to this page.

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;

Last updated