Accessing NFT Data

Guide to retrieving NFT content and metadata.

  1. Retrieve the NFT & metadata from the blockchain

  2. Retrieve the Image/media from IPFS

1. Retrieve the NFT & metadata

GhostMarket REST API provides the simplest method of retrieving the NFT Metadata in simple to digest JSON format. We monitor all supported chains and index NFT events, simplifying and standardizing the retrieval of Metadata from the disparate blockchains which we support.

see our API reference for all supported APIs

Use the API endpoint:

Use the metadata API endpoint, populating the {chain}, {contract} and {token_id} params.

https://api.ghostmarket.io/api/v2/metadata?chain={chain}&contract={contract}&tokenId={tokenId}

  • See the Blockchain Short Name table for the list of supported chain names.

  • See the NFT Contract table for current NFT contracts.

  • The token_id is an integer specifying the NFT within the collection (NFT contract)

Example:

curl -X 'GET' \
'https://api.ghostmarket.io/api/v2/metadata?chain=bsc&contract=0xF41db445D7eaF45536985cE185ce131FA4b42E68&tokenId=1 | jq .json'

The returned json object is escaped, so, should be unescaped before use. Following is an example of the unescaped object ( "\" removed for clarity ).

{
json: {
        "name": "GHOST Genesis NFT #1",
        "image": "ipfs://QmefnzTwshjRhZgMpRfRhp5Xg1hdWnWo7cnuZH8QhDmnjQ",
        "attributes": [
            {
                "trait_type": "Genesis",
                "value": true,
                "display_type": ""
            }
        ],  
        "properties": {
            "type": 2,
            "has_locked": false  
        },
        "description": "The owner of this exclusive NFT is granted 100% discount on GhostMarket trading fees, for life."
    }
}

2. Retrieve the Image/media

IPFS Media

If the image field contains one of the prefixes "ipfs://" the content must be retrieved from IPFS: Extract the IPFS hash from the image field of the metadata (The Hash is the text following the "//" in the URL), and append this to the IPFS HTTP gateway - https://ipfs.io/ipfs/{hash} URL.

e.g. Using a browser to render above image URI, browse to:

https://ipfs.io/ipfs/QmefnzTwshjRhZgMpRfRhp5Xg1hdWnWo7cnuZH8QhDmnjQ

To programmatically retrieve IPFS data, other possible alternatives for accessing IPFS is to set up your own IPFS node or use the Infura IPFS Gateway.

Non IPFS Media

If the image field points to a non IPFS URL, e.g. AWS or a generic HTTP(S) address, then directly access the image using the supplied URL.

Last updated