Transfer Token
Transfer an amount of ERC20 or ERC777 token from the sender account to the recipient account.
await api.send.transferToken(RECIPIENT_ADDRESS, TOKEN_ETHEREUM_ADDRESS, TOKEN_AMOUNT);
important
- Example
- Example Result
- JSON-RPC
- JSON-RPC Output
const AVN_API = require("avn-api");
const AVN_GATEWAY_URL = "<node_url>";
const options = {
suri: "<account_suri>",
};
const API = new AVN_API(AVN_GATEWAY_URL, options);
// This can be the address or public key.
const RECIPIENT_ADDRESS = "5DA...gxV";
// The token address on Ethereum.
const TOKEN_ETHEREUM_ADDRESS = "0x2a...b0e";
//amount of the token in 18 decimals.
const TOKEN_AMOUNT = "1234000000000000000"; //i.e. 1.234 of a token
async function main() {
await api.init();
let result = await api.send.transferToken(
RECIPIENT_ADDRESS,
TOKEN_ETHEREUM_ADDRESS,
TOKEN_AMOUNT
);
// Returns a request id
console.log(result);
}
(async () => {
await main();
})();
f1710fe7-141f-43c1-b1bb-6ec33d9b3e9a
REQUEST
POST https://AVN_GATEWAY_URL/send
HEADERS
Content-Type: application/json Authorization': bearer <awtToken>
REQUEST PARAMS
- relayer [required] - a string representing the relayer's SS58 address
- user [required] - a string representing the user's SS58 address
- payer [required] - a string representing the payer's SS58 address
- recipient [required] - a string representing the recipient's SS58 address
- token [required] - a hex string representing the token ID (20 bytes) of the token being checked
- amount [required] - a string integer value representing the amount (in lowest fraction) of the token being transferred
- nonce [required] - string integer value of the current proxy nonce of type 'token'
- proxySignature [required] - a proof signed by the user allowing the transaction to be proxied
- feePaymentSignature [required] - a proof signed by the payer allowing the relayer fees to be paid
- paymentNonce [required] - string integer value of the current payment nonce of the payer
JSON-RPC Example
curl https://AVN-API-URL/send \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: bearer <awtToken>" \
-d '{"jsonrpc":"2.0", "method":"proxyTokenTransfer", "params":{"relayer":"5FbUQ2kJWLo...Gyu6UoZaryTh", "user":"5DAgxVxKmn...rSVJDdMr", "payer":"5DAgxVxKmn...rSVJDdMr", "recipient":"5FgyNN84CzQfwHBUJWvQkr36hiQYEXjDhcUYVx9tCTdgqosF", "token":"0xb130395ae...56d676199", "amount":"1000000", "nonce":"10", "proxySignature":"0x883e4300581d...4d4500d1aab8b7832076484d967ca01c96e7ab6d20903145c9efebac38ed521f30fe52da2e27beecf08f", "feePaymentSignature":"0x7cff997be6fb...62bf6617a4c23319f666dfc2bb9e9a365ffd67ab279d980a0139fa6ce0165cdd76aaf555e7a1ba80", "paymentNonce":"199"}, "id":1}'
note
result - a request ID that can be queried for the transaction's status.
{
"jsonrpc": "2.0",
"id": 1,
"result": "8b62441c-e032-46e3-bd1d-0f8a0a764442"
}
You have now successfully submitted a transaction to the AVN.
tip
You can query the state of your transaction here using the returned result.