Transfer a ERC20 token
How to perform a fungible transfer. E.g transfer an ERC20 token from one wallet to another.
Intro
It is not possible to transfer value from a wallet without the approval of the user. Therefore to be able to transfer a token, we will need to do two things: i) create the transfer and ii) ask the user for his approval.
The object that can ask the user for his approval is called a Signer
, once we've created a Signer
object we can use the Signer
to perform the token transfer.
To perform actions on a wallet , such as transactions or signatures, the wallet has to be linked to your application. The easiest way to link a wallet to your application in to use getAccount flow. The benefits of using the getAccount flow is that this flow bundles multiple actions into one call.
Function:
//Asking the signer to transfer a certain value to a certain destination.
venlyConnect.signer.executeTokenTransfer({
walletId: '<WALLET_ID>',
to: '<BLOCKCHAIN ADDRESS>',
value: 3.1415,
tokenAddress: '<TOKEN_BLOCKCHAIN ADDRESS>',
secretType: '<BLOCKCHAIN>',
})
Example:
Address
const venlyConnect = new VenlyConnect('YOUR_CLIENT_ID');
//Asking the signer to transfer ERC20 token to a blockchain address.
venlyConnect.signer.executeTokenTransfer({
walletId: '71dec640-4eb8-4321-adb8-b79461573fc4',
to: '0xf147cA0b981C0CD0955D1323DB9980F4B43e9FED',
value: 1010,
tokenAddress: '0x02f96ef85cad6639500ca1cc8356f0b5ca5bf1d2'
secretType: 'ETHEREUM',
})
Email
const venlyConnect = new VenlyConnect('YOUR_CLIENT_ID');
//Asking the signer to transfer ERC20 tokens to an email address
venlyConnect.signer.executeTokenTransfer({
walletId: '71dec640-4eb8-4321-adb8-b79461573fc4',
to: '[email protected]',
value: 1010,
tokenAddress: '0x02f96ef85cad6639500ca1cc8356f0b5ca5bf1d2'
secretType: 'ETHEREUM',
})
The destination of a token transfer is not limited to a blockchain address, we also support email addresses and Unstoppable domains.
Returns:
{
status: "SUCCESS",
result: {
id: "be702332-8821-460c-982e-4b47d2aa4e6c",
transactionHash: "0x6838028fddf9fae2dbedfdafc117372279169832951e633079cc96a91466e550"
}
}
JS Fiddle Example
Function Reference
The function reference describes the different functions that are available in the Widget. For each function you can find the signature, its parameters, and possible options documented.
Updated about 2 months ago