Batch Tranfers for Tokens
Batch transfers are a feature in AO token contracts that let a process transfer tokens to multiple recipients in one message, instead of sending a separate message for each transfer. This is especially useful for large-scale distributions, like airdrops and rewards.
For developers you can run this script on your process (please review the batch transfer script before loading it):
This script is intended as a general-purpose extension. If your token has custom logic, you may need to replicate your custom logic inside the batch transfer handler to preserve expected behavior.
Use the provided code as a starting point, and modify as necessary to ensure compatibility with your process.
There are multiple ways to run this on the process:
aos
into process,.editor
, paste the code,.done
aos
into process,.load
with a path to a local file that contains the coderun local
aoconnect
script that sends anEval
message to the process, with theData
containing this code
Transfer with credit notices
{
"process": "TOKEN_PROCESS",
"data": "user1,amount1\nuser2,amount2",
"tags": [
{
"name": "Action",
"value": "Batch-Transfer"
}
]
}
Transfer without credit notices
{
"process": "TOKEN_PROCESS",
"data": "user1,amount1\nuser2,amount2",
"tags": [
{
"name": "Action",
"value": "Batch-Transfer"
},
{
"name": "Cast",
"value": "Any value will do here, just for the Tag to be present"
}
]
}
Reading Batch-Transfers
The classic way to detect a transfer on AO is to monitor the DEBIT and CREDIT notices, which respectively acknowledge a token transfer.
However, since batch transfers can be configured to omit CREDIT notices, the correct way to acknowledge such transfers is to look for the BATCH-DEBIT-NOTICE. This will be followed by a corresponding transfer message that includes all recipient addresses and the total amounts.
Batch transfers are atomic—if there is a batch debit notice, it guarantees that all transfers in the batch have been executed.
Last updated
Was this helpful?