Skip to content

A collection of example scripts for working with ERC-4337

License

Notifications You must be signed in to change notification settings

sunchengzhu/erc-4337-examples

 
 

Repository files navigation

项目介绍

  1. 在原erc-4337-examples项目的基础上实现了本地构造paymasterAndData的功能,而不需要通过stackup的paymaster api,这是个收费的api。
  2. 在goerli上部署并核验了用到的所有合约,方便我们直接在etherscan上调用函数以及查看数据。

前置步骤(已执行)

  1. Infinitism的discord查找goerli上最新部署的EntryPoint地址
  2. 传入offchainSigner的账户地址和EntryPoint的合约地址部署VerifyingPaymaster.sol,质押eth(addStake)、在EntryPoint为paymaster充值eth(depositTo),参考verifying_paymaster.test.ts
  3. 给simpleAccount账户转账一些eth(通过yarn run simpleAccount address查询地址)
  4. 给simpleAccount账户mint一些erc20 token

使用步骤

  1. 安装依赖:
yarn install
  1. 编译合约、生成typechain代码
yarn hardhat compile
  1. 启动bundler
    建议使用本地启动的bundler,方便查看日志,使用步骤见stackup-bundler
    需要注意的是ERC4337_BUNDLER_PRIVATE_KEY对应的账户必须持有足够支付gas fee的eth,ERC4337_BUNDLER_ETH_CLIENT_URL对应的节点必须支持debug_traceCall
    alchemy、infura、quicknode等主流的节点提供商都不支持debug_traceCall,而geth则需要full node才可以使用debug_traceCallsnap和light均不支持,这对本地机器资源要求较高。 所以我在chainlist上试了几个goerli的rpc server,下面这个看起来是可用的,测试命令如下:
curl https://goerli.blockpi.network/v1/rpc/public  \
-X POST \
-H "Content-Type: application/json" \
--data '{"method":"debug_traceCall","params":[{"from":null,"to":"0x6b175474e89094c44da98b954eedeac495271d0f","data":"0x70a082310000000000000000000000006E0d01A76C3Cf4288372a29124A26D4353EE51BE"}, "latest"],"id":1,"jsonrpc":"2.0"}'

命令

获取simpleAccount账户地址

该账户为UserOperation的sender,是向SimpleAccountFactory中的createAccount传入signingKey对应的账户地址创建出来的

yarn run simpleAccount address

eth转账

yarn run simpleAccount transfer --to <address> --amount <eth>

例子:

yarn run simpleAccount transfer --to 0x413978328AA912d3fc63929d356d353F6e854Ee1 --amount 0.001

erc20转账

yarn run simpleAccount erc20Transfer --token <address> --to <address> --amount <decimal>

例子:

yarn run simpleAccount erc20Transfer --token 0x61a89342F52d9F31626B56b64A83579E5c368f4c --to 0x413978328AA912d3fc63929d356d353F6e854Ee1 --amount 0.1

使用Paymaster

附加 --withPaymaster即可

yarn run simpleAccount:erc20Transfer --withPaymaster ...

例子:

yarn run simpleAccount erc20Transfer --token 0x61a89342F52d9F31626B56b64A83579E5c368f4c --to 0x413978328AA912d3fc63929d356d353F6e854Ee1 --amount 0.1 --withPaymaster

合约地址

EntryPoint
VerifyingPaymaster
TestToken
sender
SimpleAccountFactory

About

A collection of example scripts for working with ERC-4337

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Solidity 58.5%
  • TypeScript 36.5%
  • JavaScript 5.0%