Background
Prior to this point, registering multiple IPs or performing other operations such as minting, attaching licensing terms, and registering derivatives requires separate transactions for each operation. This can be inefficient and costly. To streamline the process, you can batch multiple transactions into a single one. Two solutions are now available for this:- Batch SPG function calls: Use SPG’s built-in
multicall
function. - Batch function calls beyond SPG: Use the Multicall3 Contract.
1. Batch SPG Function Calls via Built-in multicall
Function
SPG includes a multicall
function that allows you to combine multiple read or write operations into a single transaction.
Function Definition
Themulticall
function accepts an array of encoded call data and returns an array of encoded results corresponding to each function call:
Solidity
Example Usage
Suppose you want to mint multiple NFTs, register them as IPs, and link them as derivatives to some parent IPs. To accomplish this, you can use SPG’smulticall
function to batch the calls to the mintAndRegisterIpAndMakeDerivative
function.
Here’s how you might do it:
Solidity
mintAndRegisterIpAndMakeDerivative
using the multicall
function:
JavaScript
2. Batch Function Calls via Multicall3 Contract
The Multicall3 contract is not fully compatible with SPG functions that involve SPGNFT minting due to access control and context changes during Multicall execution. For such operations, use SPG’s built-in multicall function.
viem
library provides native support for Multicall3.
Story Aeneid Testnet Multicall3 Deployment Info
(Same address across all EVM chains)Main Functions
To batch multiple function calls, you can use the following functions:aggregate3
: Batches calls using theCall3
struct.aggregate3Value
: Similar toaggregate3
, but also allows attaching a value to each call.
Solidity
Struct Definitions
- Call3: Used in
aggregate3
. - Call3Value: Used in
aggregate3Value
.
Solidity
Return Type
- Result: Struct returned by both
aggregate3
andaggregate3Value
.
Solidity
For detailed examples in Solidity, TypeScript, and Python, see the Multicall3 repository.
Limitations
For a list of limitations when using Multicall3, refer to the Multicall3 README.Additional Resources
Full Multicall3 Interface
Solidity