From 0c6b18c5d7b6172af37c6dd87b9c91812a2587bc Mon Sep 17 00:00:00 2001 From: Ryan Goree Date: Thu, 29 Aug 2024 17:54:46 -0500 Subject: [PATCH] Refactor `evm-client-viem` to use `eth_getLogs` (#76) * Refactor `evm-client-viem` to use `eth_getLogs` * Add changeset --- .changeset/small-ravens-shake.md | 5 +++++ .../evm-client-viem/src/contract/createReadContract.ts | 7 ++----- 2 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 .changeset/small-ravens-shake.md diff --git a/.changeset/small-ravens-shake.md b/.changeset/small-ravens-shake.md new file mode 100644 index 00000000..f2541062 --- /dev/null +++ b/.changeset/small-ravens-shake.md @@ -0,0 +1,5 @@ +--- +"@delvtech/evm-client-viem": patch +--- + +Refactor `getEvents` to use `eth_getLogs` diff --git a/packages/evm-client-viem/src/contract/createReadContract.ts b/packages/evm-client-viem/src/contract/createReadContract.ts index 3873c3b4..ba6831a2 100644 --- a/packages/evm-client-viem/src/contract/createReadContract.ts +++ b/packages/evm-client-viem/src/contract/createReadContract.ts @@ -106,17 +106,14 @@ export function createReadContract({ }, 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({