Skip to main content

Transfer Non-Native Tokens

Transferring non-native tokens, such as ERC20, ERC721, or ERC1155, across wallets is an essential functionality in the decentralized finance (DeFi) space. In this tutorial, we'll guide you step by step on how to achieve this using the Eniblock SDK. Our focus will be on ERC20 tokens, but the process can be adapted for other token types as well.

Prerequisites

Before you begin, make sure you have MATICs in your wallet. If you need assistance with this step, refer to the following guide: How to top up a wallet on the Polygon Testnet.

Working with ERC20 Cryptocurrency

Getting Your ERC20 Token

First, we need to make sure that your Account has some tokens for the transfer. We'll utilize the call method of the Eniblock SDK to execute the mint method of the test ERC20 contract.

Upon successful execution, your token balance will be displayed in the editor's console.

Loading...

Transferring the ERC20 Token

With the ERC20 tokens in your account, you can now transfer them to a specific address using the following script.

Loading...

Extending to Other Token Types (ERC1155, ERC721)

Transferring ERC721 and ERC1155 tokens is just as straightforward as with ERC20. Simply replicate the same steps, adjusting the transaction object accordingly.

ERC721 Token Transfer

import { TokenType } from '@eniblock/sdk';
const transaction = {
type: TokenType.ERC721,
to: "<addressTo>",
tokenId: "<tokenId>",
contractAddress: "<contractAddress>",
};

ERC1155 Token Transfer

import { TokenType } from '@eniblock/sdk';
const transaction = {
type: TokenType.ERC1155,
to: "<addressTo>",
amount: "1",
tokenId: "<tokenId>",
contractAddress: "<contractAddress>",
};

Congratulations! You've now mastered the process of transferring non-native tokens between two wallets using the Eniblock SDK. This foundational skill opens the door to a wide range of applications and further customizations within the DeFi space. Feel free to explore and innovate!

API References

  1. Account.sendTransfer() method
  2. TransferParams interface
  3. ISendTransactionOptions interface