简体   繁体   中英

How get nft-tokens of a contract which are available in a wallet address by web3

I have a NFTs-Contract address on ethereum. I want to know a wallet address have which token of my contract. How can I get list of tokenId which are in a wallet address by web3?

const Web3 = require("web3");const provider = "https://lively-withered-grass.quiknode.pro"
const Web3Client = new Web3(new Web3.providers.HttpProvider(provider));
const minABI = [
    {
        constant: true,
        inputs: [{name: "_owner", type: "address"}],
        name: "balanceOf",
        outputs: [{name: "balance", type: "uint256"}],
        type: "function",
    },
];
const tokenAddress = "0x0d8775f648430679a709e98d2b0cb6250d2887ef";
const walletAddress = "0x1cf56Fd8e1567f8d663e54050d7e44643aF970Ce";
const contract = new Web3Client.eth.Contract(minABI, tokenAddress);
async function getBalance() {
    const result = await contract.methods.balanceOf(walletAddress).call();
    const format = Web3Client.utils.fromWei(result); // 29803630.997051883414242659
    console.log(format);
}
getBalance();

I am able to know that in a wallet address whether or not any my token but it doesn't give me any information about which token are existed in wallet.

Do you have any solution?

you must be use from etherscan.io service's(API's)

for your problem you can use this and parse information till get access your request

https://docs.etherscan.io/api-endpoints/accounts#get-a-list-of-erc721-token-transfer-events-by-address

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM