Skip to content

Commit

Permalink
Refactor evm-client-viem to use eth_getLogs (#76)
Browse files Browse the repository at this point in the history
* Refactor `evm-client-viem` to use `eth_getLogs`

* Add changeset
  • Loading branch information
ryangoree authored Aug 29, 2024
1 parent c91e643 commit 0c6b18c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-ravens-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@delvtech/evm-client-viem": patch
---

Refactor `getEvents` to use `eth_getLogs`
7 changes: 2 additions & 5 deletions packages/evm-client-viem/src/contract/createReadContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,14 @@ export function createReadContract<TAbi extends Abi = Abi>({
},

async getEvents(eventName, options) {
const filter = await publicClient.createContractEventFilter({
address: address,
const events = await publicClient.getContractEvents({
address,
abi: abi as Abi,
eventName: eventName as string,
args: options?.filter,
fromBlock: options?.fromBlock ?? 'earliest',
toBlock: options?.toBlock ?? 'latest',
});

const events = await publicClient.getFilterLogs({ filter });

return events.map(({ args, blockNumber, data, transactionHash }) => {
const objectArgs = Array.isArray(args)
? arrayToObject({
Expand Down

0 comments on commit 0c6b18c

Please sign in to comment.