Lower Tokens
Triggers a "lower" of an amount of ETH or any available ERC20 or ERC777 token, deducting the amount from the sender's AvN account.
The process is completed on Ethereum by calling the AvN tier1 contract's lower method after a summary containing the transaction has been published, in order for the recipient to receive the lowered amount.
await api.send.lowerToken(
RECIPIENT_ETHEREUM_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);
// The recipient's ethereum address
const RECIPIENT_ETHEREUM_ADDRESS = '0xfA2...a46';
const TOKEN_ETHEREUM_ADDRESS = 0
// The amount of the ERC token to be lowered in 18 decimals.
const TOKEN_AMOUNT = '300';
async function main() {
await api.init();
let result = await api.send.lowerToken(
RECIPIENT_ETHEREUM_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
- t1Recipient [required] - a string representing the t1 recipient's 20 byte Ethereum 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":"proxyTokenLower", "params":{"relayer":"5FbUQ2kJWLoq...6UoZaryTh", "user":"5DAgxVxKm...rSVJDdMr", "payer":"5DAgxVxKm...rSVJDdMr", "t1Recipient":"0xFad45995bc1ceE164E7565e301F5736F3eed3Bb1", "token":"0x405df1b38510c455ef81500a3dc7e9ae599e18f6", "amount":"3", "nonce":"10", "proxySignature":"0x8e38f2809d58c2a...b1e18552565e94981e3bece4bf71667b88e54c39340aa931872f1f332ab72b94cb9938c", "feePaymentSignature":"0x9ae648e3c25ba12ae2272024ad...13f24c884f9aac6d2cd5d0a7bff6a813140ee20e38e7374c054d31d0834250684", "paymentNonce":"10"}, "id":1}'
result - a request ID that can be queried for the transaction's status
{
"jsonrpc": "2.0",
"id": 1,
"result": "8f7f76c8-a06e-11ec-b909-0242ac120002"
}
tip
You can query the state of your transaction here using the returned request id.