Skip to content

Commit 5784e07

Browse files
Fix ERC1155 contracts meta (#250)
1 parent 3f86189 commit 5784e07

File tree

2 files changed

+58
-30
lines changed

2 files changed

+58
-30
lines changed

.changeset/curly-cows-enjoy.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 metadata resolution for ERC1155 - do not resolve name and symbol for ERC1155

packages/transaction-decoder/src/meta-strategy/nft-rpc-strategy.ts

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ContractData, ContractType } from '../types.js'
1+
import { ContractData } from '../types.js'
22
import * as RequestModel from './request-model.js'
33
import { Effect, RequestResolver } from 'effect'
44
import { PublicClient } from '../public-client.js'
@@ -53,38 +53,61 @@ export const NFTRPCStrategyResolver = (publicClientLive: PublicClient): RequestM
5353
)
5454
}
5555

56-
const erc721inst = getContract({
57-
abi: erc721Abi,
58-
address: contractAddress,
59-
client,
60-
})
56+
let meta: ContractData | undefined
6157

62-
const [name, symbol] = yield* Effect.all(
63-
[
64-
Effect.tryPromise({
65-
try: () => erc721inst.read.name(),
66-
catch: () => fail,
67-
}),
68-
Effect.tryPromise({
69-
try: () => erc721inst.read.symbol(),
70-
catch: () => fail,
71-
}),
72-
],
73-
{
74-
concurrency: 'inherit',
75-
batching: 'inherit',
76-
},
77-
)
58+
if (isERC721) {
59+
const erc721inst = getContract({
60+
abi: erc721Abi,
61+
address: contractAddress,
62+
client,
63+
})
64+
65+
const [name, symbol] = yield* Effect.all(
66+
[
67+
Effect.tryPromise({
68+
try: () => erc721inst.read.name(),
69+
catch: () => fail,
70+
}),
71+
Effect.tryPromise({
72+
try: () => erc721inst.read.symbol(),
73+
catch: () => fail,
74+
}),
75+
],
76+
{
77+
concurrency: 'inherit',
78+
batching: 'inherit',
79+
},
80+
)
81+
82+
meta = {
83+
address,
84+
contractAddress: address,
85+
contractName: name,
86+
tokenSymbol: symbol,
87+
type: 'ERC721',
88+
chainID: chainId,
89+
}
90+
}
7891

79-
const type: ContractType = isERC1155 ? 'ERC1155' : 'ERC721'
92+
if (isERC1155) {
93+
meta = {
94+
address,
95+
contractAddress: address,
96+
type: 'ERC1155',
97+
chainID: chainId,
98+
}
99+
}
80100

81-
const meta: ContractData = {
82-
address,
83-
contractAddress: address,
84-
contractName: name,
85-
tokenSymbol: symbol,
86-
type,
87-
chainID: chainId,
101+
if (!meta) {
102+
// Contract exists but doesn't support NFT interfaces - this is a "no data found" case
103+
return yield* Effect.fail(
104+
new RequestModel.MissingMetaError(
105+
address,
106+
chainId,
107+
'nft-rpc-strategy',
108+
'Contract is not an NFT (ERC721/ERC1155)',
109+
),
110+
)
88111
}
89112

90113
return meta

0 commit comments

Comments
 (0)