Using the Generic Multicaller Handler Contract
Creating a Transaction for an Aave Deposit (Example #1)
Crafting the Message
// Ethers V6
import { ethers } from "ethers";
function generateMessageForMulticallHandler(
userAddress,
aaveAddress,
depositAmount,
depositCurrency,
aaveReferralCode
) {
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
// Define the ABI of the functions
const approveFunction = "function approve(address spender, uint256 value)";
const depositFunction = "function deposit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode)";
// Create Interface instances
const erc20Interface = new ethers.Interface([approveFunction]);
const aaveInterface = new ethers.Interface([depositFunction]);
// Encode the function calls with selectors
const approveCalldata = erc20Interface.encodeFunctionData("approve", [aaveAddress, depositAmount]);
const depositCalldata = aaveInterface.encodeFunctionData("deposit", [depositCurrency, depositAmount, userAddress, aaveReferralCode]);
// Encode the Instructions object
return abiCoder.encode(
[
"tuple(" +
"tuple(" +
"address target," +
"bytes callData," +
"uint256 value" +
")[]," +
"address fallbackRecipient" +
")"
],
[
[
[
[depositCurrency, approveCalldata, 0],
[aaveAddress, depositCalldata, 0],
],
userAddress
]
]
);
}
const myMessage = generateMessageForMulticallHandler("your-wallet-address", "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2", "10", "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "0")
console.log(myMessage)Generating the Deposit
What happens after the deposit is received on the destination chain?
Message Constraints
Conclusion
Creating a Transaction for WrapChoice (Example #2)
Charging Protocol Fees (Example #3)
Creating a Transaction for a Uniswap Swap (Example #4)
Reverting Transactions
Summarized Requirements
Security & Safety Considerations
Last updated