简体   繁体   English

如何通过 web3 获取钱包地址中可用的合约的 nft 代币

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

I have a NFTs-Contract address on ethereum.我在以太坊上有一个 NFT 合约地址。 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?如何通过 web3 获取钱包地址中的 tokenId 列表?

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)您必须使用 etherscan.io 服务(API)

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 https://docs.etherscan.io/api-endpoints/accounts#get-a-list-of-erc721-token-transfer-events-by-address

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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