# NFT Query

## Initialize the contract object

```
var Contract = require('web3-eth-contract');
Contract.setProvider('wss://polygon-mainnet.blastapi.io/1160f5ab-4dfa-4ac1-aec4-12c7214ee252');
//jsonInterface:Contract ABI，address:Contract Address
var myContract = new Contract(jsonInterface,address);
```

***JsonInterface can be viewed in the blockchain browser, such as the polygon example:***

<figure><img src="/files/1sGamNbHbB5FeWwtPMx4" alt=""><figcaption></figcaption></figure>

## Query NFT Count of ERC1155

```
//walletAddress:Wallet Address，tokenId：TokenId of ERC1155 NFT 
myContract.methods["balanceOf"](walletAddress,tokenId).call({}) 
    .then(function(result){ 
    ///Return the number of tokenIds held
});
```

***Example:***

```
const myFirstPromise = new Promise((resolve, reject) => {
    myContract.methods["balanceOf"]("0xa9e9412AE9761B6c8AF6Bc76498208F773c5aEc3",11).call({})
    .then(function(result){ 
    if(result >= 1){
        resolve(true);
    }else{
        resolve(false);
    }
    });
});

myFirstPromise.then((hasNFT) => {
    console.log(`${hasNFT}`);
})
```

## Query NFT Metadata of ERC1155

```
const mySecondPromise = new Promise((resolve, reject) => {
    myContract.methods["uri"](tokenId).call({})
    .then(function(result){
        resolve(result);
    });
});
```

***Example:***

```
const mySecondPromise = new Promise((resolve, reject) => {
    myContract.methods["uri"](11).call({})
    .then(function(result){//result uri of metadata
        resolve(result);
    });
});

mySecondPromise.then((result) => {
    console.log(result);//return:https://static.pallet.zone/metadata/WorldcupChampion/11.json
})
```

***Parsing Metadata Result from URI:***<https://static.pallet.zone/metadata/WorldcupChampion/11.json>

```
{
    "name": "Bit - Qatar(QA)",
    "description": "Bit - Qatar(QA)",
    "image": "https://static.pallet.zone/wordcup/Qatar.png"
}
```

## Query NFT Count of ERC721

```
myContract.methods["balanceOf"](walletAddress).call({}) 
    .then(function(result){ 
    if(result >= 1){
        resolve(true);
    }else{
        resolve(false);
    }
    });
});

myFirstPromise.then((hasNFT) => {
    console.log(`${hasNFT}`);
})
```

***Example:***

```
const myFirstPromise = new Promise((resolve, reject) => {
    myContract.methods["balanceOf"]("0xa9e9412AE9761B6c8AF6Bc76498208F773c5aEc3").call({})
    .then(function(result){ 
    if(result >= 1){
        resolve(true);
    }else{
        resolve(false);
    }
    });
});

myFirstPromise.then((hasNFT) => {
    console.log(`${hasNFT}`);
})
```

## Query NFT Metadata of ERC721

```
const mySecondPromise = new Promise((resolve, reject) => {
    myContract.methods["tokenUri"](tokenId).call({})
    .then(function(result){
        resolve(result);
    });
});

mySecondPromise.then((result) => {
    console.log(result);
})
```

***Example:***

```
const mySecondPromise = new Promise((resolve, reject) => {
    myContract.methods["tokenUri"](2061).call({})
    .then(function(result){
        resolve(result);
    });
});

mySecondPromise.then((result) => {
    console.log(result);//return metadata uri：https://static.pallet.zone/metadata/GenesisNFT/pallet
})
```

**Parsing Metadata Results from URI:**&#x20;

```
{
    "name": "Pallet Genesis",
    "description": "Pallet Genesis NFT is linked to user’s Pallet wallet address with plenty of benefits and privileges like - Free-mint NFT, airdrops, discounts in coming campaigns or activities on Pallet",
    "image": "https://static.pallet.zone/genesis/pallet.webp"
}
```


---

# 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://pallet-1.gitbook.io/pallet-white-paper/developers/2-wallet-sdk-integration/2.2-deeplink/nft-query.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.
