Skip to content

Commit

Permalink
metadata get improved
Browse files Browse the repository at this point in the history
  • Loading branch information
arietrouw committed Nov 4, 2023
1 parent cfcaca3 commit e1d3b46
Show file tree
Hide file tree
Showing 4 changed files with 294 additions and 35 deletions.
250 changes: 250 additions & 0 deletions .yarn/versions/42277a0b.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
releases:
"@xyo-network/abstract-archivist": patch
"@xyo-network/abstract-bridge": patch
"@xyo-network/abstract-diviner": patch
"@xyo-network/abstract-witness": patch
"@xyo-network/account": patch
"@xyo-network/account-model": patch
"@xyo-network/address": patch
"@xyo-network/address-payload-plugin": patch
"@xyo-network/api": patch
"@xyo-network/api-models": patch
"@xyo-network/archivist": patch
"@xyo-network/archivist-abstract": patch
"@xyo-network/archivist-indexeddb": patch
"@xyo-network/archivist-model": patch
"@xyo-network/archivist-model-mongodb": patch
"@xyo-network/archivist-mongodb": patch
"@xyo-network/archivist-wrapper": patch
"@xyo-network/automation-witness-server": patch
"@xyo-network/axios": patch
"@xyo-network/bip39": patch
"@xyo-network/blockchain-payload-plugins": patch
"@xyo-network/blockchain-plugins": patch
"@xyo-network/blocknative-ethereum-gas-payload-plugin": patch
"@xyo-network/blocknative-ethereum-gas-plugin": patch
"@xyo-network/boundwitness": patch
"@xyo-network/boundwitness-builder": patch
"@xyo-network/boundwitness-model": patch
"@xyo-network/boundwitness-validator": patch
"@xyo-network/boundwitness-wrapper": patch
"@xyo-network/bowser-system-info-payload-plugin": patch
"@xyo-network/bowser-system-info-plugin": patch
"@xyo-network/bridge": patch
"@xyo-network/bridge-model": patch
"@xyo-network/bridge-module-resolver": patch
"@xyo-network/bridge-wrapper": patch
"@xyo-network/cli": patch
"@xyo-network/coingecko-crypto-market-payload-plugin": patch
"@xyo-network/coingecko-crypto-market-plugin": patch
"@xyo-network/config-payload-plugin": patch
"@xyo-network/core": patch
"@xyo-network/crypto-address-transaction-history-payload-plugin": patch
"@xyo-network/crypto-address-transaction-history-plugin": patch
"@xyo-network/crypto-asset-payload-plugin": patch
"@xyo-network/crypto-asset-plugin": patch
"@xyo-network/crypto-cards-game-payload-plugin": patch
"@xyo-network/crypto-cards-game-plugin": patch
"@xyo-network/crypto-cards-move-payload-plugin": patch
"@xyo-network/crypto-cards-move-plugin": patch
"@xyo-network/crypto-cards-payload-plugins": patch
"@xyo-network/crypto-cards-plugins": patch
"@xyo-network/crypto-contract-function-read-payload-plugin": patch
"@xyo-network/crypto-contract-function-read-plugin": patch
"@xyo-network/crypto-contract-payload-plugin": patch
"@xyo-network/crypto-contract-plugin": patch
"@xyo-network/crypto-market-payload-plugins": patch
"@xyo-network/crypto-market-plugins": patch
"@xyo-network/crypto-nft-collection-diviner-score-plugin": patch
"@xyo-network/crypto-nft-collection-payload-plugin": patch
"@xyo-network/crypto-nft-collection-witness-plugin": patch
"@xyo-network/crypto-nft-diviner-score-plugin": patch
"@xyo-network/crypto-nft-payload-plugin": patch
"@xyo-network/crypto-nft-payload-plugins": patch
"@xyo-network/crypto-nft-plugin": patch
"@xyo-network/crypto-nft-plugins": patch
"@xyo-network/crypto-nft-score-model": patch
"@xyo-network/crypto-nft-witness-wallet-plugin": patch
"@xyo-network/crypto-payload-plugins": patch
"@xyo-network/crypto-plugins": patch
"@xyo-network/diviner": patch
"@xyo-network/diviner-address-chain": patch
"@xyo-network/diviner-address-chain-abstract": patch
"@xyo-network/diviner-address-chain-memory": patch
"@xyo-network/diviner-address-chain-model": patch
"@xyo-network/diviner-address-history": patch
"@xyo-network/diviner-address-history-model": patch
"@xyo-network/diviner-address-space": patch
"@xyo-network/diviner-address-space-abstract": patch
"@xyo-network/diviner-address-space-memory": patch
"@xyo-network/diviner-address-space-model": patch
"@xyo-network/diviner-boundwitness": patch
"@xyo-network/diviner-boundwitness-abstract": patch
"@xyo-network/diviner-boundwitness-memory": patch
"@xyo-network/diviner-boundwitness-model": patch
"@xyo-network/diviner-boundwitness-stats": patch
"@xyo-network/diviner-boundwitness-stats-abstract": patch
"@xyo-network/diviner-boundwitness-stats-memory": patch
"@xyo-network/diviner-boundwitness-stats-model": patch
"@xyo-network/diviner-coin": patch
"@xyo-network/diviner-coin-user-locations": patch
"@xyo-network/diviner-coin-user-locations-abstract": patch
"@xyo-network/diviner-coin-user-locations-model": patch
"@xyo-network/diviner-forecasting": patch
"@xyo-network/diviner-forecasting-abstract": patch
"@xyo-network/diviner-forecasting-memory": patch
"@xyo-network/diviner-forecasting-method-arima": patch
"@xyo-network/diviner-forecasting-model": patch
"@xyo-network/diviner-image-thumbnail": patch
"@xyo-network/diviner-model": patch
"@xyo-network/diviner-models": patch
"@xyo-network/diviner-mongodb": patch
"@xyo-network/diviner-payload": patch
"@xyo-network/diviner-payload-abstract": patch
"@xyo-network/diviner-payload-memory": patch
"@xyo-network/diviner-payload-model": patch
"@xyo-network/diviner-payload-stats": patch
"@xyo-network/diviner-payload-stats-abstract": patch
"@xyo-network/diviner-payload-stats-memory": patch
"@xyo-network/diviner-payload-stats-model": patch
"@xyo-network/diviner-schema-list": patch
"@xyo-network/diviner-schema-list-abstract": patch
"@xyo-network/diviner-schema-list-memory": patch
"@xyo-network/diviner-schema-list-model": patch
"@xyo-network/diviner-schema-stats": patch
"@xyo-network/diviner-schema-stats-abstract": patch
"@xyo-network/diviner-schema-stats-memory": patch
"@xyo-network/diviner-schema-stats-model": patch
"@xyo-network/diviner-transform": patch
"@xyo-network/diviner-transform-abstract": patch
"@xyo-network/diviner-transform-memory": patch
"@xyo-network/diviner-transform-model": patch
"@xyo-network/diviner-wrapper": patch
"@xyo-network/dns": patch
"@xyo-network/domain": patch
"@xyo-network/domain-payload-plugin": patch
"@xyo-network/domain-plugin": patch
"@xyo-network/elevation-payload-plugin": patch
"@xyo-network/elevation-plugin": patch
"@xyo-network/error": patch
"@xyo-network/etherchain-ethereum-gas-v2-payload-plugin": patch
"@xyo-network/etherchain-ethereum-gas-v2-plugin": patch
"@xyo-network/etherchain-gas-ethereum-blockchain-payload-plugins": patch
"@xyo-network/etherchain-gas-ethereum-blockchain-plugins": patch
"@xyo-network/ethereum-blockchain-payload-plugins": patch
"@xyo-network/ethereum-blockchain-plugins": patch
"@xyo-network/ethers-ethereum-gas-payload-plugin": patch
"@xyo-network/ethers-ethereum-gas-plugin": patch
"@xyo-network/etherscan-ethereum-gas-payload-plugin": patch
"@xyo-network/etherscan-ethereum-gas-plugin": patch
"@xyo-network/ethgasstation-ethereum-gas-payload-plugin": patch
"@xyo-network/express-node": patch
"@xyo-network/express-node-dependencies": patch
"@xyo-network/express-node-lib": patch
"@xyo-network/express-node-middleware": patch
"@xyo-network/express-node-routes": patch
"@xyo-network/express-node-server": patch
"@xyo-network/express-node-test": patch
"@xyo-network/filesystem-archivist": patch
"@xyo-network/gas-ethereum-blockchain-payload-plugins": patch
"@xyo-network/gas-ethereum-blockchain-plugins": patch
"@xyo-network/gas-price-payload-plugin": patch
"@xyo-network/gas-price-plugin": patch
"@xyo-network/hash": patch
"@xyo-network/http-bridge": patch
"@xyo-network/huri": patch
"@xyo-network/id-payload-plugin": patch
"@xyo-network/id-plugin": patch
"@xyo-network/image-thumbnail-payload-plugin": patch
"@xyo-network/image-thumbnail-plugin": patch
"@xyo-network/info-system-payload-plugins": patch
"@xyo-network/info-system-plugins": patch
"@xyo-network/key-model": patch
"@xyo-network/location-certainty-payload-plugin": patch
"@xyo-network/location-certainty-plugin": patch
"@xyo-network/location-payload-plugin": patch
"@xyo-network/location-plugin": patch
"@xyo-network/logger": patch
"@xyo-network/manifest": patch
"@xyo-network/manifest-model": patch
"@xyo-network/memory-archivist": patch
"@xyo-network/metamask-connector": patch
"@xyo-network/module": patch
"@xyo-network/module-abstract": patch
"@xyo-network/module-abstract-mongodb": patch
"@xyo-network/module-events": patch
"@xyo-network/module-instance-payload-plugin": patch
"@xyo-network/module-instance-plugin": patch
"@xyo-network/module-model": patch
"@xyo-network/module-model-mongodb": patch
"@xyo-network/module-mongodb": patch
"@xyo-network/module-resolver": patch
"@xyo-network/module-wrapper": patch
"@xyo-network/modules": patch
"@xyo-network/network": patch
"@xyo-network/node": patch
"@xyo-network/node-abstract": patch
"@xyo-network/node-app": patch
"@xyo-network/node-core-lib": patch
"@xyo-network/node-core-model": patch
"@xyo-network/node-core-modules-mongo": patch
"@xyo-network/node-core-types": patch
"@xyo-network/node-memory": patch
"@xyo-network/node-model": patch
"@xyo-network/node-system-info-payload-plugin": patch
"@xyo-network/node-system-info-plugin": patch
"@xyo-network/node-wrapper": patch
"@xyo-network/object": patch
"@xyo-network/object-identity": patch
"@xyo-network/payload": patch
"@xyo-network/payload-builder": patch
"@xyo-network/payload-model": patch
"@xyo-network/payload-plugin": patch
"@xyo-network/payload-plugins": patch
"@xyo-network/payload-validator": patch
"@xyo-network/payload-wrapper": patch
"@xyo-network/payloadset-plugin": patch
"@xyo-network/payloadset-plugins": patch
"@xyo-network/pentair-payload-plugin": patch
"@xyo-network/pentair-plugin": patch
"@xyo-network/plugins": patch
"@xyo-network/previous-hash-store": patch
"@xyo-network/previous-hash-store-indexeddb": patch
"@xyo-network/previous-hash-store-model": patch
"@xyo-network/previous-hash-store-storage": patch
"@xyo-network/prometheus-node-plugin": patch
"@xyo-network/promisable": patch
"@xyo-network/promise": patch
"@xyo-network/protocol": patch
"@xyo-network/quadkey": patch
"@xyo-network/query-payload-plugin": patch
"@xyo-network/schema-cache": patch
"@xyo-network/schema-name-validator": patch
"@xyo-network/schema-payload-plugin": patch
"@xyo-network/schema-plugin": patch
"@xyo-network/sdk": patch
"@xyo-network/sdk-xyo-client-js": patch
"@xyo-network/sdk-xyo-mongo-js": patch
"@xyo-network/sentinel": patch
"@xyo-network/sentinel-abstract": patch
"@xyo-network/sentinel-model": patch
"@xyo-network/shared": patch
"@xyo-network/system-payload-plugins": patch
"@xyo-network/system-plugins": patch
"@xyo-network/typeof": patch
"@xyo-network/uniswap-crypto-market-payload-plugin": patch
"@xyo-network/uniswap-crypto-market-plugin": patch
"@xyo-network/url-payload-plugin": patch
"@xyo-network/url-plugin": patch
"@xyo-network/url-safety-payload-plugin": patch
"@xyo-network/url-safety-plugin": patch
"@xyo-network/value-payload-plugin": patch
"@xyo-network/wallet-model": patch
"@xyo-network/wasm": patch
"@xyo-network/witness": patch
"@xyo-network/witness-environment": patch
"@xyo-network/witness-model": patch
"@xyo-network/witness-timestamp": patch
"@xyo-network/witness-wrapper": patch
"@xyo-network/witnesses": patch
"@xyo-network/worker-bridge": patch
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { NftContractInformation } from './NftContractInformation'
import { NftMetadata } from './NftMetadata'

export interface NftInfoFields extends NftContractInformation {
metaDataUri?: string
metadata?: NftMetadata
metadataUri?: string
supply: string
tokenId: string
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { JsonRpcProvider } from '@ethersproject/providers'
import { AxiosJson } from '@xyo-network/axios'
import { NftInfo, NftMetadata, NftSchema, toTokenType } from '@xyo-network/crypto-nft-payload-plugin'
import { ERC721URIStorage__factory, ERC1155Supply__factory } from '@xyo-network/open-zeppelin-typechain'

import { getNftCollectionMetadata } from './getNftCollectionMetadata'
import { NftMetadata } from '@xyo-network/crypto-nft-payload-plugin'
import { ERC721URIStorage__factory, ERC1155URIStorage__factory } from '@xyo-network/open-zeppelin-typechain'

const ipfsGateway = '5d7b6582.beta.decentralnetworkservices.com'

Expand All @@ -30,7 +28,7 @@ export const checkIpfsUrl = (urlToCheck: string, ipfsGateway: string) => {
}
}

export const getNftFields = async (
export const getNftMetadata = async (
/**
* The address of the NFT contract to search for
*/
Expand All @@ -45,29 +43,30 @@ export const getNftFields = async (
* multiple of 100 as that appears to be the default page size.
*/
tokenId: string,
): Promise<NftInfo> => {
): Promise<[string | undefined, NftMetadata | undefined]> => {
const axios = new AxiosJson({ timeout: 2000 })
const storage = ERC721URIStorage__factory.connect(contractAddress, provider)
const supply1155 = ERC1155Supply__factory.connect(contractAddress, provider)
const { type: nftType } = await getNftCollectionMetadata(contractAddress, provider)
const storage1155 = ERC1155URIStorage__factory.connect(contractAddress, provider)

let supply: string | undefined
let uri1155: string | undefined
try {
supply = nftType === toTokenType('ERC1155') ? (await supply1155.totalSupply(tokenId)).toHexString() : '0x01'
uri1155 = await storage1155.uri(tokenId)
} catch (ex) {
const error = ex as Error
console.error(`supply: ${error.message}`)
console.error(`metaDataUri: ${error.message}`)
}

let metaDataUri: string | undefined
let metadataUri: string | undefined
try {
metaDataUri = await storage.tokenURI(tokenId)
metadataUri = await storage.tokenURI(tokenId)
} catch (ex) {
const error = ex as Error
console.error(`metaDataUri: ${error.message}`)
console.error(`metadataUri: ${error.message}`)
}

const checkedMetaDataUri = metaDataUri ? checkIpfsUrl(metaDataUri, ipfsGateway) : metaDataUri
const tokenMetadataUri = metadataUri ?? uri1155

const checkedMetaDataUri = tokenMetadataUri ? checkIpfsUrl(tokenMetadataUri, ipfsGateway) : tokenMetadataUri
let metadata: NftMetadata | undefined = undefined
try {
metadata = checkedMetaDataUri ? (await axios.get(checkedMetaDataUri)).data : undefined
Expand All @@ -76,15 +75,5 @@ export const getNftFields = async (
console.error(`metadata: ${error.message}`)
}

const info: NftInfo = {
address: contractAddress,
chainId: provider.network.chainId,
metaDataUri,
metadata,
schema: NftSchema,
supply: supply ?? '1',
tokenId,
type: nftType,
}
return info
return [tokenMetadataUri, metadata]
}
Loading

0 comments on commit e1d3b46

Please sign in to comment.