Multicall
Utility methods of the Azoth SDK for getting token information and configuration
multicall()
multicall()Executes multiple contract calls in a single transaction. This method allows you to combine multiple operations into one transaction, saving gas and improving user experience.
async multicall(data: string[]): Promise<ethers.TransactionResponse>Parameters:
data: Array of encoded function call data (bytes). Each element should be the result ofcontract.interface.encodeFunctionData().
Returns: An ethers.js TransactionResponse object.
Example:
// Encode deposit call
const depositData = papaya.contract.interface.encodeFunctionData("deposit", [
formatInput('100', 6), // amount
false // isPermit2
]);
// Encode subscribe call
const subscribeData = papaya.contract.interface.encodeFunctionData("subscribe", [
'0x...', // author address
convertRatePerSecond('100', RatePeriod.MONTH), // rate per second
0 // projectId
]);
// Execute both operations in one transaction
// Order is important: deposit first, then subscribe
const tx = await papaya.multicall([depositData, subscribeData]);
await tx.wait();
console.log('Multicall transaction completed!');Use Cases:
Combining deposit and subscribe operations
Batch operations for better UX
Atomic execution of multiple related operations
Note: The order of operations in the array matters. Make sure dependent operations come after their prerequisites (e.g., deposit before subscribe).
Last updated