Batch calls we use oftenly, like Approve then Swap, Approve then TransferFrom, user needs to confirm twice or more in wallet, we put the calls into a JSON, so that the wallet can deal the calls automatic in just one confirm. Here’s the JSON example:
let json = {
rpc: {
name: 'Scroll_Alpha',
url: 'https://alpha-rpc.scroll.io/l2',
chainId: 534353
},
calls: [
{
to: '0x67aE69Fd63b4fc8809ADc224A9b82Be976039509',
value: '0',
abi: 'function transfer(address to, uint256 amount)', //transfer ERC20
params: [
'0xE44081Ee2D0D4cbaCd10b44e769A14Def065eD4D',
'1000000'
]
},
{
to: '0xE44081Ee2D0D4cbaCd10b44e769A14Def065eD4D',
value: '1000000000000000000',
abi: '', //transfer ETH
params: []
}
]
}
The abi standard is defined in ethers.js, this JSON send from app to wallet, and the wallet’s encode function is:
const { BigNumber, utils } = require('ethers')
let interface = new utils.Interface([call.abi])
let funcName = call.abi.slice(9, call.abi.indexOf('('))
let data = interface.encodeFunctionData(funcName, call.params)
then sign the data with Private key.
In this case, wallet knows each call, the total spend(This’s what user really care about) can be calculated before submit. It’s useful for not only EOA but also SmartContractAccount(like AA).