Skip to content

Commit 47b4225

Browse files
authored
Experimental erc20 fix crash when no address provided (#188)
1 parent d34983a commit 47b4225

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

.changeset/funny-coats-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@3loop/transaction-decoder': patch
3+
---
4+
5+
Fix crash in experimental erc20 resolver when address is empty. We provide an empty address when we decode logs for errors

packages/transaction-decoder/src/abi-strategy/experimental-erc20.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { erc20Abi, getAddress, getContract } from 'viem'
55

66
const getLocalFragments = (service: PublicClient, { address, chainId }: RequestModel.GetContractABIStrategy) =>
77
Effect.gen(function* () {
8+
if (!address)
9+
return yield* Effect.fail(new RequestModel.ResolveStrategyABIError('local-strategy', address, chainId))
10+
811
const client = yield* service
912
.getPublicClient(chainId)
1013
.pipe(
@@ -13,10 +16,16 @@ const getLocalFragments = (service: PublicClient, { address, chainId }: RequestM
1316
),
1417
)
1518

16-
const inst = getContract({
17-
abi: erc20Abi,
18-
address: getAddress(address),
19-
client: client.client,
19+
const inst = yield* Effect.try({
20+
try: () =>
21+
getContract({
22+
abi: erc20Abi,
23+
address: getAddress(address),
24+
client: client.client,
25+
}),
26+
catch: () => {
27+
throw new RequestModel.ResolveStrategyABIError('local-strategy', address, chainId)
28+
},
2029
})
2130

2231
const decimals = yield* Effect.tryPromise({

0 commit comments

Comments
 (0)