Expose raw events / make filter blocks adjustable #504
Replies: 2 comments 7 replies
-
|
publicClient.getLogs({
address: CONTRACT_ADDRESS,
event: getAbiItem({
abi: CONTRACT_ABI,
name: 'MyEvent',
}),
args: {
typedArg: 'something',
},
fromBlock: 0n,
}), |
Beta Was this translation helpful? Give feedback.
-
|
You can do the same pattern with
That's correct, because you can also specify an optional block range to vanilla |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, i'm trying to migrate a codebase to viem and having some issues.
With typechain you can use
contract.filters.Transfer()and similar to get a generic filter which you can then pass to e.g. queryFilter ascontract.queryFilter(event, fromBlock, toBlock).This is quite useful as often rpcs(even paid ones) have block range restrictions, so to get all the events you can write some generic iteration like e.g.
In viem as I understand the docs there are two ways to query the events log:
using
getFilterLogscreateEventFiltermangles the from/to block into the id, and doesn't expose a getter or setter for the blockRange so it's not well suited for generic iteration. I don't understandwhythe blocks are passed to id creation - probably sth caching related. Anyhow imo would go good to make the blocks manipulatable.Generally design wise seems quite unintentional to me, that the block configuration is on the
createEventFilter, not thegetFilterLogsusing
getLogsusing getLogs kinda works but you're losing the typing & autocomplete on the event. It's weird that i have to manually generate the signature as the information is already available in
contract.createEventFilter.Transfer.Therefore I'm wondering if it would make sense to expose an
contract.events.<Transfer>which can be used in combination withgetLogs.related: #260
Beta Was this translation helpful? Give feedback.
All reactions