Skip to content

Commit 6f23034

Browse files
committed
Experimental erc20 fix crash when no address provided
1 parent d34983a commit 6f23034

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { erc20Abi, getAddress, getContract } from 'viem'
55

66
const getLocalFragments = (service: PublicClient, { address, chainId }: RequestModel.GetContractABIStrategy) =>
77
Effect.gen(function* () {
8+
if (address === '') return Effect.fail(new RequestModel.ResolveStrategyABIError('local-strategy', address, chainId))
9+
810
const client = yield* service
911
.getPublicClient(chainId)
1012
.pipe(
@@ -13,11 +15,13 @@ const getLocalFragments = (service: PublicClient, { address, chainId }: RequestM
1315
),
1416
)
1517

16-
const inst = getContract({
17-
abi: erc20Abi,
18-
address: getAddress(address),
19-
client: client.client,
20-
})
18+
const inst = yield* Effect.try(() =>
19+
getContract({
20+
abi: erc20Abi,
21+
address: getAddress(address),
22+
client: client.client,
23+
}),
24+
)
2125

2226
const decimals = yield* Effect.tryPromise({
2327
try: () => inst.read.decimals(),

0 commit comments

Comments
 (0)