How to Fetch User Operations (UserOps) for a Specific Wallet Address
While Account Abstraction (ERC-4337) continues to gain momentum, so does our infrastructure evolve to be able to understand on-chain events. In a domain where transactions are not indexed conventionally, this guide teaches you how to efficiently filter and retrieve UserOps pertaining to a particular user. This is particularly useful for Account Abstraction wallet developers who want to show user activity, but it may be useful for many other development purposes.
Prerequisites
Familiarity with Account Abstraction.
Familiarity with REST APIs.
How Does an Account Abstraction (ERC-4337) Transaction Work?
First, let’s break down these new types of transactions in a simple format and clarify the terminology to help our understanding.
Starting with UserOps:
A UserOp is a structure that describes a transaction to be sent on behalf of a user. Based on the user's instructions, their smart contract account generates UserOps detailing what they want to do (e.g., send, receive tokens, interact with a contract).
Moving to Bundlers:
Bundlers listen to the mempool for UserOps, validate them, and bundle multiple validated ones together.
They package multiple UserOperation objects into a single call to a global EntryPoint contract.
Execution by EntryPoint Contracts:
The EntryPoint contract is a central contract to execute bundles of UserOperations.
The EntryPoint contract performs further validations, ensuring everything is correct, and then executes each transaction in the UserOps.
https://github.com/eth-infinitism/account-abstraction/releases/tag/v0.6.0
How to Filter UserOp Data for a Specific Wallet Address
When we view the transactions to the EntryPoint contract on Etherscan, they all have the same Method, and the From address is the address of the bundler sending the UserOps to the EntryPoint contract.
The details of the transaction are contained in the logs, including the UserOperationEvent
all of which share the same topic hash: 0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f
The challenge is, with so much data all going to the same contract, how do we find and retrieve just the UserOps pertaining to a specific user?
Fortunately, there is a simple way to do this. If you look at the Topics for the UserOperationEvent
, you’ll find that index_topic_2
is the sender address, i.e. the smart contract account (wallet address) of the user who originally created this UserOp.
So now, utilizing this information, let’s fetch and retrieve the UserOps for a specific wallet address using the GoldRush API.
1
Get Log Events By Topic Hash
chainName
parameter by selecting the blockchain you’d like to query. On the browser, there is a sidebar to select from, but in the terminal, you can either type the chainName
or its ID.topicHash
of the UserOperationEvent
. Again, they all have the same topic hash, which is 0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f
.2
Filter by User Address
UserOperationEvent
, we can make use of the secondary-topics
query parameter for this endpoint, inputting the specific wallet address we would like to fetch UserOps for. Then, we just need to specify a block range.3
Run
indexed address sender
value, not as the sender_address
at the top of the response which is actually the EntryPoint contract.How to Get UserOp Transactions (with Logs) by Address
Okay, so what we’ve covered so far allows you to fetch just the UserOps pertaining to a wallet address. However, this UserOp is only one event log in a complete transaction, and doesn’t provide the full context of a user’s on-chain activities. So, what we might really be interested in are the transactions containing UserOps, for a given wallet address. To get these, we’re going to use GoldRush’s transactions endpoints.
1
Get Transactions for Address
2
Run
tx_hash
(transaction hash).3
Filter by Account Abstraction Transactions
sender_address
value 0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789
. You can verify this in the sample response above.sender_address
field of the GoldRush API response!Conclusion
Utilizing the powerful capabilities of the GoldRush API, you can now deftly sift through Account Abstraction data, extracting UserOps specific to individual wallet addresses, or all a user’s transactions containing UserOps. This newfound knowledge paves the way for enhanced transaction insights and new use cases!