Skip to main content

Transfer

This page instructs you how to transfer assets from a logged-in users Passport wallet to another wallet.

Pre-requisites

  • The user must be logged into your application via Passport

1. Creating the transfer

Once you have a user logged into your application via Passport, you will be able to initiate the transfer of an asset (ETH, ERC20 or ERC721) from the users Passport wallet to another wallet. To do this, we must create an UnsignedTransferRequest argument that will be passed to the transfer function. The structure of the UnsignedTransferRequest varies depending on the type property, which specifies the type of asset that is being transferred. You'll need to ensure that the wallet that you're attempting to transfer the asset from is in fact the owner, otherwise the transfer request will fail.

1.1. Transferring an ERC721

To transfer an ERC721, the following properties must be specified:

  • type: The type of asset to transfer. Must be ERC721
  • tokenId: The unique identifier of the NFT to be transferred
  • tokenAddress: The address of the ERC721 contract to be transferred
  • receiver: The address of the wallet that will receive the ERC721

For example:

const transferRequest: UnsignedTransferRequest = {
type: 'ERC721',
tokenId: '1295',
receiver: '0x0000000000000000000000000000000000000000',
tokenAddress: '0xacb3c6a43d15b907e8433077b6d38ae40936fe2c',
};

1.2. Transferring an ERC20

To transfer ERC20, the following properties must be specified:

  • type: The type of asset to transfer. Must be ERC20
  • amount: The amount of the ERC20 token to be transferred
  • receiver: The address of the wallet that will receive the ERC20
  • tokenAddress: The address of the ERC20 contract to be transferred

For example:

const transferRequest: UnsignedTransferRequest = {
type: 'ERC20',
amount: '1',
receiver: '0x0000000000000000000000000000000000000000',
tokenAddress: '0xacb3c6a43d15b907e8433077b6d38ae40936fe2c',
};

1.3. Transferring ETH

To transfer ETH, the following properties must be specified:

  • type: The type of asset to transfer. Must be ETH
  • amount: The amount of the ERC20 token to be transferred
  • receiver: The address of the wallet that will receive the ETH

For example:

const transferRequest: UnsignedTransferRequest = {
type: 'ETH',
amount: '1',
receiver: '0x0000000000000000000000000000000000000000',
};

2. Performing the transfer

Once you've created an UnsignedTransferRequest, it's time to perform the transfer. This can be done by calling the transfer function on the IMXProvider instance that is returned from the connectImx function:

const transferResponse: CreateTransferResponseV1 = await provider.transfer(transferRequest);

The transfer function returns a promise that resolves to a CreateTransferResponseV1, which contains the following properties:

  • sent_signature: The signature of the transfer that was executed
  • status: The status of the transfer
  • time: The time that the transfer occurred
  • transfer_id: The unique identifier for the transfer

In the event of a failure, the promise will reject with the following properties:

  • code: The error code associated with the failure
  • details: A string containing details about the failure
    • message: A string containing a message that describes the failure

IMX Whitepaper IMX Tokenomics Block Explorer Careers Contact Us