# Metadata

### Token URI

To pull in off-chain metadata for ERC721 NFTs, your contract need to return a URI where we can find the metadata. To find this URI, we use the `tokenURI` method in ERC721.

A tokenURI function may look something like this in your contract:

```
/**
 * @dev See {IERC721Metadata-tokenURI}.
 */
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
    require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token");

    string memory _tokenURI = _tokenURIs[tokenId];
    string memory base = _baseURI();

    // If there is no base URI, return the token URI.
    if (bytes(base).length == 0) {
        return _tokenURI;
    }
    // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
    if (bytes(_tokenURI).length > 0) {
        return string(abi.encodePacked(base, _tokenURI));
    }

    return super.tokenURI(tokenId);
}



```

Ultimately, the function needs to return an http or IPFS url, which returns a JSON object containing the metadata for the token queried.

### Metadata structure

```
{
  "description": "My project or NFT description.",
  "image": "https://mystorageapi/image", 
  "animation_url": "https://thisismyvideo.mystorage.com", 
  "name": "My NFT Name",
  "attributes": [ ... ], 
}
```

### Attributes

![](/files/7jLeaZLDQCsAjnifoRco)

```
{
"attributes": [
    {
      "trait_type": "Background", 
      "value": "Orange"
    }, 
    {
      "trait_type": "Eye Color", 
      "value": "Blue"
    }, 
    {
      "trait_type": "Face", 
      "value": "Casual Smile"
    }, 
    {
      "trait_type": "Shell", 
      "value": "Corn Tortilla"
    }, 
    {
      "trait_type": "Filling", 
      "value": "Beef"
    }
  ]
}
```

`trait_type` is the name of the trait, `value` is the value of the trait. Values are of type `string` (aka text between quotes).

### IPFS

If you use [IPFS](https://ipfs.io/) to host your metadata, your URL should be in the format `ipfs://<hash>`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.campfire.exchange/fundamentals/metadata.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
