Step 4: We check the balance of our Counter contract in theSponsorPaymaster(with balances(address)) and then we addDepositFor{value}(counterAddress).
console.log('Before UserOp. Counter:', counter.count());// We add the deposit to the counter contract in the paymasterif (_sponsorPaymaster.balances(computed) <=1e14) { _sponsorPaymaster.addDepositFor{value:5e16}(computed); console.log('Adding paymaster balance to counter', computed); } else { console.log('Counter already has balance to pay for tx', computed); }
Step 5: In AA, all operations need to be pack in a UserOperation, we can do this thanks to the KintoWallet.
// Let's send a transaction to the counter contract through our walletuint startingNonce = _newWallet.getNonce();uint256[] memory privateKeys =newuint256[](1); privateKeys[0] = deployerPrivateKey; UserOperation memory userOp =this.createUserOperationWithPaymasterCustomGas( block.chainid,address(_newWallet), startingNonce, privateKeys,address(counter),0, abi.encodeWithSignature('increment()'),address(_sponsorPaymaster), [uint256(5000000),3,3] ); UserOperation[] memory userOps =new UserOperation[](1); userOps[0] = userOp;
Step 6: Execute the transaction via theentry point.