- Users only need to wait for a single batched transaction to execute, instead of multiple individual transactions.
- Users pay less in gas fees, as batched transactions cost less than multiple individual transactions.
- Transactions are atomic: if any transaction in the batch reverts, the entire batch reverts.
contractExecution
endpoint.
Example: Batch transfer
The following example demonstrates how to generate a call to thecontractExecution endpoint that batches two USDC transfer transactions. This
example uses an MSCA wallet, on the ETH-SEPOLIA testnet.
This code creates the encoding of the transfer function calls that make up the
abiParameters data for the call to the contractExecution endpoint:
Javascript
transfer
function, the call is then specified twice in the abiParameters field of the
call to the contractExecution endpoint.
JSON
executeBatch((address address, uint256 amount, bytes func)[]). The address
is the USDC contract address, amount is 0 (the amount of native token
transferred), and func is the encoded function call generated by the sample
code. The example provides the parameters twice, so the resulting batched
transactions result in 200 USDC transferred (100 for each transaction).
Example: Batching CCTP approve and depositForBurn
The following example demonstrates how to generate a call to thecontractExecution endpoint that batches two related transactions: approve,
and depositForBurn in the CCTP contract. This example uses an MSCA wallet, on
the ETH-SEPOLIA testnet.
This code creates the encoding of the two calls that make up the abiParameters
data for the call to the contractExecution endpoint.
Javascript
approve(address spender, uint256 value). Calling approve allows
the spender to spend value USDC on your behalf. This is necessary for the
subsequent depositForBurn transaction in the batch. In this example, address
is the TokenMessenger contract address and the value is 100000000 (100
USDC). Note that the example code encodes the parameters of the function call,
the subsequent call to the Circle API specifies the contract address to make the
call to.
The second transaction in the batch is a call to the function on the
TokenMessenger contract:
depositForBurn(uint256 amount, uint32 destinationDomain, bytes32 mintRecipient, address burnToken).
Calling depositForBurn results in the TokenMessenger contract transferring
and burning the specified amount of USDC from the wallet on the origin chain.
The parameters to the depositForBurn call are:
amount: the amount of USDC to burn. In this example,100000000(100 USDC)destinationDomain: a Circle-issued identifier for a network where Circle deploys CCTP contracts. In this example,2to specify Avalanche. For a full list, see the CCTP domain list.mintRecipient: the destination address, encoded as a Solidity address.burnToken: the contract address of the token to burn. In this example, the USDC contract on the source chain.
contractExecution endpoint like
this:
JSON
executeBatch((address address, uint256 amount, bytes func)[]). The parameters
for each transaction are:
-
approveaddressis the USDC token contract addressamountis the amount of native tokens transferredfuncis the encoded function call generated by the sample code
-
depositForBurnaddressis theTokenMessengercontract addressamountis the amount of native tokens transferredfuncis the encoded function call generated by the sample code