简体   繁体   English

检索 web3 contract.ownerOf NFT ERC721

[英]retrieving web3 contract.ownerOf NFT ERC721

I'm playing around with web3 and frontend trying to read something off the ethereum blockchain.我正在玩 web3 和前端,试图从以太坊区块链中读取一些东西。 What i wanted to do is to verify the owner of a NFT (erc721).我想做的是验证 NFT (erc721) 的所有者。

I've used this piece of code here that enable me to check the balanceOf a certain ERC20 linked to the connected wallet address我在这里使用了这段代码,它使我能够检查链接到连接的钱包地址的某个 ERC20 的余额

  function getERC20TokenBalance(tokenAddress, walletAddress, callback) {

  let minABI = [
    // balanceOf
    {
      "constant":true,
      "inputs":[{"name":"_owner","type":"address"}],
      "name":"balanceOf",
      "outputs":[{"name":"balance","type":"uint256"}],
      "type":"function"
    },
    // decimals
    {
      "constant":true,
      "inputs":[],
      "name":"decimals",
      "outputs":[{"name":"","type":"uint8"}],
      "type":"function"
    }
  ];

  let contract = web3.eth.contract(minABI).at(tokenAddress);
  
  contract.balanceOf(walletAddress, (error, balance) => {
    // ERC20トークンの decimals を取得
    contract.decimals((error, decimals) => {
      balance = balance.div(10**decimals);
      console.log(balance.toString());
      callback(balance);
    });
  });
  
}

setInterval(function() {
  let tokenAddress = '0x50f5474724e0ee42d9a4e711ccfb275809fd6d4a';
    let walletAddress = web3.eth.accounts[0];
          if(tokenAddress != "" && walletAddress != "") {
        getERC20TokenBalance(tokenAddress, walletAddress, (balance) => {
          document.getElementById('text-bal').innerText = balance.toFixed(3);
        });        
      };
        }, 100);

now i would like to verify a certain NFT, which i used 0x50f5474724e0ee42d9a4e711ccfb275809fd6d4a (a SANDBOX land contract).现在我想验证某个 NFT,我使用了 0x50f5474724e0ee42d9a4e711ccfb275809fd6d4a(SANDBOX 土地合同)。 With balanceOf, it does show me this address has LAND NFT in it, but i wanted to check for the tokenID, by changing it to使用 balanceOf,它确实显示该地址中有 LAND NFT,但我想检查 tokenID,将其更改为

let contract = web3.eth.contract(minABI).at(tokenAddress);
contract.ownerOf('18429');

it returns nothing, can you guys point me to the right direction:)?它什么也没返回,你们能指出我正确的方向吗:)?

token are not on the balance of the contract, they are inside of it.代币不在合约的余额上,它们在合约里面。 According to the erc721 - you have to invoke the balanceOf method of the contract.根据erc721 - 你必须调用合约的balanceOf方法。

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

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