stackup-wallet / erc-4337-examples Goto Github PK
View Code? Open in Web Editor NEWA collection of example scripts for working with ERC-4337
Home Page: https://docs.stackup.sh/docs/erc-4337-examples
License: MIT License
A collection of example scripts for working with ERC-4337
Home Page: https://docs.stackup.sh/docs/erc-4337-examples
License: MIT License
I'm running my Geth node and stackup bundler on my machine. When I run yarn run simpleAccount transfer --to <address> --amount 0.01
. I got the following error:
error: Error: pending ops: replacement op must increase maxFeePerGas and MaxPriorityFeePerGas by >= 10%
at getResult (/server2/weihan/erc-4337-examples/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:142:28)
at processJsonFunc (/server2/weihan/erc-4337-examples/node_modules/@ethersproject/web/src.ts/index.ts:383:22)
at /server2/weihan/erc-4337-examples/node_modules/@ethersproject/web/src.ts/index.ts:320:42
at step (/server2/weihan/erc-4337-examples/node_modules/@ethersproject/web/lib/index.js:33:23)
at Object.next (/server2/weihan/erc-4337-examples/node_modules/@ethersproject/web/lib/index.js:14:53)
at fulfilled (/server2/weihan/erc-4337-examples/node_modules/@ethersproject/web/lib/index.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: -32602,
data: 'pending ops: replacement op must increase maxFeePerGas and MaxPriorityFeePerGas by >= 10%'
},
requestBody: '{"method":"eth_sendUserOperation","params":[{"sender":"0xFC901229E04ca3fB830a5658A09807a7D5a012AF","nonce":"0x0","initCode":"0x71d63edcda95c61d6235552b5bc74e32d8e2527b5fbfb9cf0000000000000000000000009c85856d30cff8847939adbae5bddf3f7c549f960000000000000000000000000000000000000000000000000000000000000000","callData":"0xb61d27f6000000000000000000000000519eaeb4fd8986e2bc8a23741f2bf84fff3b2857000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000","callGasLimit":"0x5580","verificationGasLimit":"0x65139","maxFeePerGas":"0x51b5f0c4a","maxPriorityFeePerGas":"0x285c28","paymasterAndData":"0x","preVerificationGas":"0xaf9c","signature":"0xadc7c317397fba318fe075654586d4cb90ff1de3b92dd9ce271bca0f8403b571159dbc6924c3b50b40862369ff9426117d7930053669020dca1afec6dd500e7e1c"},"0x0576a174D229E3cFA37253523E645A78A0C91B57"],"id":43,"jsonrpc":"2.0"}',
requestMethod: 'POST',
url: 'http://localhost:4337'
}
Here's the Geth node command:
./go-ethereum/build/bin/geth --goerli --datadir /server2/weihan/ethereum/execution/datadir --http --http.api="eth,web3,net,debug" --http.vhosts="*" --http.corsdomain "*" --authrpc.jwtsecret=/opt/jwtsecret --authrpc.vhosts="*"
May I ask if there's any solution to this issue?
Hi, I'm getting the following error when using the stackup-wallet/erc-4337-examples package from a React application project context:
Uncaught ReferenceError: Buffer is not defined
at ./node_modules/@account-abstraction/utils/dist/src/ERC4337Utils.js
Looks like it's coming from the @account-abstraction package. Apparently it's a deprecated one. Are there any fixes planned for this?
Everything works fine when calling these examples from this project or another non-React environment
I'm following Stackup guide and programmed an app.js by that guide. But when I run NodeJS this error throwed:
statusCode: 401, responseText: 'project id required in the url\n
So, how can I find the project ID and how to include it into the url?
Hey, i would like to transfer some eth from my userAccount to my wallet account, but i got an error : reason: 'missing revert data in call exception; Transaction reverted without a reason string', code: 'CALL_EXCEPTION', data: '0x', transaction: { to: '0x0576a174D229E3cFA37253523E645A78A0C91B57', data: '0x35567e1a000000000000000000000000703022bf7725b36a9057eb86986544e3596c2f520000000000000000000000000000000000000000000000000000000000000000', accessList: null },
here is my command : yarn run simpleAccount transfer --to 0x274a4E4F93082738F1c142a9040C3DFAa632245e --amount 0.01
and i have 0.5 Goerli ETH on my userAccount.
Tried to create wallet using following command
$yarn run simpleAccount address
Later fund some eth to generated address then tried the following
$ yarn run simpleAccount transfer --to 0x17462eA99F7D4502347d629Dbd6f866Ee54E38E1 --amount 0.008
yarn run v1.22.19
$ ts-node scripts/simpleAccount/index.ts transfer --to 0x17462eA99F7D4502347d629Dbd6f866Ee54E38E1 --amount 0.008
Balance: 33844250040317952
Signed UserOperation: {
"sender": "0xd99D99a8d0bca1119403f1789721549ccCa9AE72",
"nonce": "0x0",
"initCode": "0x71d63edcda95c61d6235552b5bc74e32d8e2527b5fbfb9cf00000000000000000000000047b76a2dad532a791f2484ca47e0a25615384e3c0000000000000000000000000000000000000000000000000000000000000000",
"callData": "0xb61d27f600000000000000000000000017462ea99f7d4502347d629dbd6f866ee54e38e1000000000000000000000000000000000000000000000000001c6bf52634000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
"callGasLimit": "0x5580",
"verificationGasLimit": "0x65139",
"maxFeePerGas": "0x5a7e9",
"maxPriorityFeePerGas": "0x5a776",
"paymasterAndData": "0x",
"preVerificationGas": "0xaf84",
"signature": "0x1700fb614ad4ffde2c8664ae46462bab3a813d3c8bd6a5f9fa13e8f20bf387e2540ce6baedfdcb8291e3a9f3fa688d785178f12fe17270d7588b72b0a50728771c"
}
C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\logger\src.ts\index.ts:269
const error: any = new Error(message);
^
Error: processing response error (body="{"error":{"code":-32602,"data":"preVerificationGas: below expected gas of 48140","message":"preVerificationGas: below expected gas of 48140"},"id":43,"jsonrpc":"2.0"}", error={"code":-32602,"data":"preVerificationGas: below expected gas of 48140"}, requestBody="{"method":"eth_sendUserOperation","params":[{"sender":"0xd99D99a8d0bca1119403f1789721549ccCa9AE72","nonce":"0x0","initCode":"0x71d63edcda95c61d6235552b5bc74e32d8e2527b5fbfb9cf00000000000000000000000047b76a2dad532a791f2484ca47e0a25615384e3c0000000000000000000000000000000000000000000000000000000000000000","callData":"0xb61d27f600000000000000000000000017462ea99f7d4502347d629dbd6f866ee54e38e1000000000000000000000000000000000000000000000000001c6bf52634000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000","callGasLimit":"0x5580","verificationGasLimit":"0x65139","maxFeePerGas":"0x5a7e9","maxPriorityFeePerGas":"0x5a776","paymasterAndData":"0x","preVerificationGas":"0xaf84","signature":"0x1700fb614ad4ffde2c8664ae46462bab3a813d3c8bd6a5f9fa13e8f20bf387e2540ce6baedfdcb8291e3a9f3fa688d785178f12fe17270d7588b72b0a50728771c"},"0x0576a174D229E3cFA37253523E645A78A0C91B57"],"id":43,"jsonrpc":"2.0"}", requestMethod="POST", url="https://api.blocknative.com/v1/goerli/bundler", code=SERVER_ERROR, version=web/5.7.1)
at Logger.makeError (C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\logger\src.ts\index.ts:269:28)
at Logger.throwError (C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\logger\src.ts\index.ts:281:20)
at C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\web\src.ts\index.ts:341:28
at step (C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\web\lib\index.js:33:23)
at Object.next (C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\web\lib\index.js:14:53)
at fulfilled (C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\web\lib\index.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
reason: 'processing response error',
code: 'SERVER_ERROR',
body: '{"error":{"code":-32602,"data":"preVerificationGas: below expected gas of 48140","message":"preVerificationGas: below expected gas of 48140"},"id":43,"jsonrpc":"2.0"}',
error: Error: preVerificationGas: below expected gas of 48140
at getResult (C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\providers\src.ts\json-rpc-provider.ts:142:28)
at processJsonFunc (C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\web\src.ts\index.ts:383:22)
at C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\web\src.ts\index.ts:320:42
at step (C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\web\lib\index.js:33:23)
at Object.next (C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\web\lib\index.js:14:53)
at fulfilled (C:\Users\Omkar Sai Sunku\Documents\Micro1\indexx\erc-4337-examples\node_modules@ethersproject\web\lib\index.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: -32602,
data: 'preVerificationGas: below expected gas of 48140'
},
requestBody: '{"method":"eth_sendUserOperation","params":[{"sender":"0xd99D99a8d0bca1119403f1789721549ccCa9AE72","nonce":"0x0","initCode":"0x71d63edcda95c61d6235552b5bc74e32d8e2527b5fbfb9cf00000000000000000000000047b76a2dad532a791f2484ca47e0a25615384e3c0000000000000000000000000000000000000000000000000000000000000000","callData":"0xb61d27f600000000000000000000000017462ea99f7d4502347d629dbd6f866ee54e38e1000000000000000000000000000000000000000000000000001c6bf52634000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000","callGasLimit":"0x5580","verificationGasLimit":"0x65139","maxFeePerGas":"0x5a7e9","maxPriorityFeePerGas":"0x5a776","paymasterAndData":"0x","preVerificationGas":"0xaf84","signature":"0x1700fb614ad4ffde2c8664ae46462bab3a813d3c8bd6a5f9fa13e8f20bf387e2540ce6baedfdcb8291e3a9f3fa688d785178f12fe17270d7588b72b0a50728771c"},"0x0576a174D229E3cFA37253523E645A78A0C91B57"],"id":43,"jsonrpc":"2.0"}',
requestMethod: 'POST',
url: 'https://api.blocknative.com/v1/goerli/bundler'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Following the instructions with some assistance from the video tutorial, I am getting the attached error.
yarn run simpleAccount erc20Transfer --token 0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e --to <existing address> --amount 0.1
With this setup, yarn run simpleAccount address
produced SimpleAccount address: 0x0000000000000000000000000000000000000000
as the output, with the following logged in the local node:
WARN [03-10|13:33:30.709] Served eth_call conn=127.0.0.1:52652 reqid=44 duration="581.499µs" err="execution reverted"
errdata=0x6ca7b8060000000000000000000000000000000000000000000000000000000000000000
To remedy this, I installed the smart contract from the account-abstraction project by cloning that project and running the deploy script, e.g. yarn deploy --network localhost
and updating config.json with the address of the freshly deployed SimpleAccountFactory address.
After deploying the account abstraction into the local environment, yarn run simpleAccount address
produced an address as expected.
Thank you for providing various examples, which have been helpful in understanding Abstraction Account. I was able to reproduce other parts successfully, but I am having issues with the implementation of batchERC20Transfer
and batchTransfer
. When called, I receive the following error message:
{
....
"reason": "Error: VM Exception while processing transaction: reverted with reason string 'account: not Owner or EntryPoint'",
....
}
Upon further investigation, I found that the issue occurs when passing the encodeFunctionData(executeBatch)
as a parameter to accountAPI.createSignedUserOp
.
erc-4337-examples/scripts/simpleAccount/batchErc20Transfer.ts
Lines 63 to 68 in c7902cb
within the implementation of accountAPI, the encodeFunctionData(executeBatch)
is re-encoded as execute
, and this results in an error when execute is called again within executeBatch
.
It seems that a modification to the bundler SDK of eth-infinitism is necessary to support executeBatch.
I am trying to implement a simple proof-of-concept wallet that would be able to make USDC transfers and pay for gas in USDC.
I have a smart account with 10 USDC on it's balance (basescan).
This is what i'm trying to do:
Presets.Builder.SimpleAccount
preset with Paymaster of type erc20token
.However, when I run the code, I get an error message that says "processing response error" and "simulation: insufficient token payments". Here is the error message:
reason: 'processing response error',
code: 'SERVER_ERROR',
body: '{"error":{"code":-32601,"data":"simulation: insufficient token payments","message":"simulation: insufficient token payments"},"id":42,"jsonrpc":"2.0"}'
And here's the code I'm running:
import { ethers, Contract, Signer, Wallet } from "ethers";
import { Client, Presets } from "userop";
import { usdcAbi } from "./usdc-abi";
const entryPointAddress = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
const usdcAddress = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913";
const rpcUrl = "https://api.stackup.sh/v1/node/API_KEY";
const paymasterUrl = "https://api.stackup.sh/v1/paymaster/API_KEY";
const recipient = "RECEPIENT_ADDRESS";
const smartAccountOwnerPrivateKey = "smart account owner private key";
const lightAccountFactoryAddress = "0x00000055C0b4fA41dde26A74435ff03692292FBD";
// I'm using LightAccount from Alchemy. I've also tried SimpleAccount, results are the same
// const simpleAccountFactoryAddress = "0x15Ba39375ee2Ab563E8873C8390be6f2E2F50232";
async function sendTransferUserOp(
signer: Signer,
usdc: Contract,
recipientAddress: string
) {
const builder = await Presets.Builder.SimpleAccount.init(
signer,
rpcUrl,
{
factory: lightAccountFactoryAddress,
paymasterMiddleware: Presets.Middleware.verifyingPaymaster(paymasterUrl, {
type: "erc20token",
token: usdcAddress,
}),
}
);
const address = builder.getSender();
console.log(`Smart account address: ${address}`);
console.log(`Balance: ${await usdc.balanceOf(address)}`); // 10000000
const client = await Client.init(rpcUrl);
const amount = ethers.utils.parseUnits("5", 6);
const res = await client.sendUserOperation(
builder.executeBatch(
[usdcAddress, usdcAddress],
[
usdc.interface.encodeFunctionData("approve", [
entryPointAddress,
amount,
]),
usdc.interface.encodeFunctionData("transfer", [
recipientAddress,
amount,
]),
]
),
{
onBuild: (op) => console.log("Signed UserOperation:", op),
}
);
console.log(`UserOpHash: ${res.userOpHash}`);
console.log("Waiting for transaction...");
const ev = await res.wait();
console.log(`Transaction hash: ${ev?.transactionHash ?? null}`);
}
async function main() {
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const signer = new Wallet(smartAccountOwnerPrivateKey, provider);
console.log(`Wallet address: ${await signer.getAddress()}`);
const contract = new Contract(usdcAddress, usdcAbi, signer);
const call = await sendTransferUserOp(signer, contract, recipient);
}
main();
Also a question: why does the doc and examples say that ERC-20 approve
call is needed? According to ERC-20 standard approve is required for transferFrom
call and is not needed for direct transfer
.
I don't get and I'm curiouss, why to use a stackup-bundler if I can have the same functionality and nothing more with plain RPC-calls and a wallet where I own the private key.
Let's discuss the examples:
yarn run simpleAccount address
this will always return the same address and I can do nothing with it besides transfering tokens and ETH/Matic, that I own on this address:
yarn run simpleAccount transfer --to <address> --amount <eth>
So it is basically nothing else than I could achieve with a "normal" wallet-address where I even own the Private key.
I would understand if the Bundler would allow me to act on someone else's behalf. At least this is how I understand account abstraction. But all examples only transfer "my" own assets from the address that has been created with yarn run simpleAddress address
.
What am I not seeing here?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.