🎴Transfer Tokens

Transfer ERC20 tokens on any blockchain - ETH (Ethereum), BNB (Binance Smart Chain), MATIC (Polygon)

Transfer ERC20 Tokens

To transfer ERC20 tokens, follow the steps:

  1. Construct anoptionsobject and set

    1. type:"erc20"

    2. amount: Moralis.Units.Token("0.5", "18") //Converts towei

    3. receiver: "0x000..." //wallet address

    4. contractAddress: "0x..." //contract of the ERC20 token

  2. Call the Moralis transfer function as shown below

// sending 0.5 tokens with 18 decimals
const options = {
  type: "erc20",
  amount: Moralis.Units.Token("0.5", "18"),
  receiver: "0x..",
  contractAddress: "0x..",
};
let result = await Moralis.transfer(options);

By using Moralis.Units.Tokenhelper function you can multiply the amount you want to send by the number of decimals. This is required to construct an ERC20 transaction.

The contract address and the number of decimals for a token can normally be found on Etherscan or on the website of the project.

Get the address and decimals programmatically of a token by using Moralis SDK Moralis.Web3API.token.getTokenMetadataBySymbol().

Resolving the results

Moralis.transfer() returns a transaction response after it is executed. The below page shows how to consume the data returned.

🤝pageResolve Transfer

Last updated