You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We wanted to implement gasless smart accounts (EIP-7702) using ZeroDev infrastructure. In simple terms: instead of sending our transactions with eth_sendTransaction we will be sending it with eth_sendUserOperation to their bundler RPC.
The problem was that we had to change all our functions to work with this new library. So instead of:
The Zerodev team created an "adapter" to transform the kernelClient (a smart account client) to a signer:
import{KernelEIP1193Provider}from'@zerodev/sdk/providers';import{ethers}from'ethers';// Ensure to initialize your KernelClient hereconstkernelClient=…;// Initialize the KernelEIP1193Provider with your KernelClientconstkernelProvider=newKernelEIP1193Provider(kernelClient);// Use the KernelProvider with ethersconstethersProvider=newethers.BrowserProvider(kernelProvider);constsigner=awaitethersProvider.getSigner();
This provider maps every request made from the signer eth_sendTransaction to a eth_sendUserOperation. In other terms: it makes you feel you have a local signer of your smart account rather than a normal External Owned Account (EOA). You can check the provider code here.
Side idea: I think ether.js could do integrate this adapter natively so existing projects could use EIP-7702 without changing a lot of their codebase
Interacting with contracts (OK)
Everything works seamlessly when interacting with contracts. E.g:
constcontract=RandomContractFactory.connect(contractAddress,signer);constvotes=contract.getVotes();// RandomContractFactory.sol implements a getVotes() function that returns the votes
...
So no code changes right? Not so fast...
Deploying contracts with factory (FAIL)
I encountered a problem with the factory.deploy() function because ZeroDev delegates a call to a on-chain contract that executes the code and deploys the transaction itself. I modified the ZeroDev library to bypass this problem and it worked 🥳 . But then I noticed that the contract address set up in the contract was not right:
constfactory=newRandomContractFactory(signer);constcontract=awaitfactory.deploy(5n);constcontractAddress=awaitcontract.getAddress();// it would be an empty "Address" in etherscan and not a "Contract" address
This is caused because the factory code computes the address from the sender and nonce (it is assuming the contract is deployed by an EOA):
I am assuming that all delegate calls would emit an event similar to event ContractCreation(address indexed newContract);. If we want to do it more generic we could allow the developer to send the ABI Item that would return the deployed contract address in the overrides parameter.
Final thoughts
If you think it is a good idea I could open a PR and implement it. I noticed that you have a Discussions section but the only thing related to Account Abstraction or EIP-7702 I found was this issue (and this issue in the Issues section). I thought this solution was straight forward and I decided to open the issue to check for your comments.
Thank you for your time. This became a little more extensive that I thought.
Cheers,
Nico
Code Example
The text was updated successfully, but these errors were encountered:
Describe the Feature
Problem
I love the simplicity of using etherjs's
signer
when interacting with contracts. We built our project libraries and functions relying on it. E.g:We wanted to implement gasless smart accounts (EIP-7702) using ZeroDev infrastructure. In simple terms: instead of sending our transactions with
eth_sendTransaction
we will be sending it witheth_sendUserOperation
to their bundler RPC.The problem was that we had to change all our functions to work with this new library. So instead of:
we will be doing something like
Zerodev tutorial to deploy contracts here.
This mean code duplication and that is bad news.
Current Solution
The Zerodev team created an "adapter" to transform the
kernelClient
(a smart account client) to asigner
:This provider maps every request made from the signer
eth_sendTransaction
to aeth_sendUserOperation
. In other terms: it makes you feel you have a local signer of your smart account rather than a normal External Owned Account (EOA). You can check the provider code here.Side idea: I think ether.js could do integrate this adapter natively so existing projects could use EIP-7702 without changing a lot of their codebase
Interacting with contracts (OK)
Everything works seamlessly when interacting with contracts. E.g:
So no code changes right? Not so fast...
Deploying contracts with factory (FAIL)
I encountered a problem with the
factory.deploy()
function because ZeroDev delegates a call to a on-chain contract that executes the code and deploys the transaction itself. I modified the ZeroDev library to bypass this problem and it worked 🥳 . But then I noticed that the contract address set up in the contract was not right:This is caused because the factory code computes the address from the sender and nonce (it is assuming the contract is deployed by an EOA):
ethers.js/src.ts/contract/factory.ts
Line 112 in 0195f44
In these cases, the contract is deployed by another contract so the computed address do not match the deployed contract address.
Solution in ethers.js
I created a small patch for our project that looks like this:
I think we could implement this natively in ethers.js by adding a couple of extra things:
Set the transaction type
4
oreip-7702
(my reference) in theoverrides
parameter of thefactory.deploy
function:ethers.js/src.ts/contract/factory.ts
Line 104 in 0195f44
If the type is
4
oreip-7702
then wait for the transaction to happen and with the receipt execute the line:if not then keep the normal flow.
I am assuming that all delegate calls would emit an event similar to
event ContractCreation(address indexed newContract);
. If we want to do it more generic we could allow the developer to send the ABI Item that would return the deployed contract address in theoverrides
parameter.Final thoughts
If you think it is a good idea I could open a PR and implement it. I noticed that you have a Discussions section but the only thing related to Account Abstraction or EIP-7702 I found was this issue (and this issue in the Issues section). I thought this solution was straight forward and I decided to open the issue to check for your comments.
Thank you for your time. This became a little more extensive that I thought.
Cheers,
Nico
Code Example
The text was updated successfully, but these errors were encountered: