Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curly-cows-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@3loop/transaction-decoder': patch
---

Fix metadata resolution for ERC1155 - do not resolve name and symbol for ERC1155
83 changes: 53 additions & 30 deletions packages/transaction-decoder/src/meta-strategy/nft-rpc-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContractData, ContractType } from '../types.js'
import { ContractData } from '../types.js'
import * as RequestModel from './request-model.js'
import { Effect, RequestResolver } from 'effect'
import { PublicClient } from '../public-client.js'
Expand Down Expand Up @@ -53,38 +53,61 @@ export const NFTRPCStrategyResolver = (publicClientLive: PublicClient): RequestM
)
}

const erc721inst = getContract({
abi: erc721Abi,
address: contractAddress,
client,
})
let meta: ContractData | undefined

const [name, symbol] = yield* Effect.all(
[
Effect.tryPromise({
try: () => erc721inst.read.name(),
catch: () => fail,
}),
Effect.tryPromise({
try: () => erc721inst.read.symbol(),
catch: () => fail,
}),
],
{
concurrency: 'inherit',
batching: 'inherit',
},
)
if (isERC721) {
const erc721inst = getContract({
abi: erc721Abi,
address: contractAddress,
client,
})

const [name, symbol] = yield* Effect.all(
[
Effect.tryPromise({
try: () => erc721inst.read.name(),
catch: () => fail,
}),
Effect.tryPromise({
try: () => erc721inst.read.symbol(),
catch: () => fail,
}),
],
{
concurrency: 'inherit',
batching: 'inherit',
},
)

meta = {
address,
contractAddress: address,
contractName: name,
tokenSymbol: symbol,
type: 'ERC721',
chainID: chainId,
}
}

const type: ContractType = isERC1155 ? 'ERC1155' : 'ERC721'
if (isERC1155) {
meta = {
address,
contractAddress: address,
type: 'ERC1155',
chainID: chainId,
}
}

const meta: ContractData = {
address,
contractAddress: address,
contractName: name,
tokenSymbol: symbol,
type,
chainID: chainId,
if (!meta) {
// Contract exists but doesn't support NFT interfaces - this is a "no data found" case
return yield* Effect.fail(
new RequestModel.MissingMetaError(
address,
chainId,
'nft-rpc-strategy',
'Contract is not an NFT (ERC721/ERC1155)',
),
)
}

return meta
Expand Down
Loading