Building Account Abstraction ERC-4337 (Part-2) Execute callData

Shishir Singh
cumberlandlabs
Published in
2 min readJul 23, 2023
Dehradun Uttarakhand

In Part-1 of this series, we built an on-chain wallet contract with Execute method and Alice key as the wallet owner. In this article, we will invoke the Execute method of the wallet contract and transfer a few WETH tokens to Bob's public key. Test data is right here.

To execute the call data, let’s first build a sample call data to transfer a few WETH tokens from Alice to Bob. Function composeWETHTransferCallData()

We have already funded our wallet address in the code's init() function. The entry point contract will use this ETH to pay gas to the execute method. Modify the init() function as below. First, we prepare the call data and pass it to executeHandleOps():

async function init() {

await initAddresses() ;

// await composeInitCode(); // Already executed in Part-1

// await fundContractsAndAddresses() ; // Already executed in Part-1

await composeWETHTransferCallData();

// await executeHandleOps(initCode,'0x', false) ;

// await executeHandleOps(initCode,'0x', true) ;

await executeHandleOps('0x',callData, false) ; // Execute call data here

// await composeWETHTransferCallData();

// await executeHandleOps('0x',callData, true) ;

await getBalance() ;

}

We can see the successful transaction with Bob's WETH token balance changed to 0.01 WETH

Handleops Success -->  0x5e052cf8fc28d91158896797b9b00232cc6012331377d22c3de5279779eb1428
Alice ETH Balance 4790.998004326175016756
Alice sender wallet 0x0131656c221e4F779f270045d3B2dEeF70219A39 ETH Balance 1.979220694827756292
Alice WETH Balance 0.5
Alice sender wallet 0x0131656c221e4F779f270045d3B2dEeF70219A39 WETH Balance 0.24
Bob WETH Balance 0.01

Below is the sequence diagram of what we have just executed above in the code:

Execute call data operation via On-chain wallet contract

What we have just witnessed in the above code execution is Alice’s on-chain wallet contract has executed the WETH transfer transaction instead of a regular off-chain wallet signing the transaction and sending it over to the RPC node.

Future Business Opportunities

Bundler-as-a-service: Entities can bundle multiple such transactions and bundle them to be executed on-chain. e.g in the above code block, we have witnessed one such transaction where Alice transferred 0.01 WETH to Bob. Service providers can execute multiple such user operations into one bundle.

Next Steps

In this operation, we have seen a user on-chain wallet paying for the gas for the WETH transfer. What if the user doesn't want to pay the gas on their own and wants to leverage a sponsorship of the gas payment to a 3rd party? We will explore the Paymaster contract in the next part of this series.

--

--