|
1 | | -import { ContractData, ContractType } from '../types.js' |
| 1 | +import { ContractData } from '../types.js' |
2 | 2 | import * as RequestModel from './request-model.js' |
3 | 3 | import { Effect, RequestResolver } from 'effect' |
4 | 4 | import { PublicClient } from '../public-client.js' |
@@ -53,38 +53,61 @@ export const NFTRPCStrategyResolver = (publicClientLive: PublicClient): RequestM |
53 | 53 | ) |
54 | 54 | } |
55 | 55 |
|
56 | | - const erc721inst = getContract({ |
57 | | - abi: erc721Abi, |
58 | | - address: contractAddress, |
59 | | - client, |
60 | | - }) |
| 56 | + let meta: ContractData | undefined |
61 | 57 |
|
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 | + } |
78 | 91 |
|
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 | + } |
80 | 100 |
|
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 | + ) |
88 | 111 | } |
89 | 112 |
|
90 | 113 | return meta |
|
0 commit comments