I'm playing around with web3 and frontend trying to read something off the ethereum blockchain. What i wanted to do is to verify the owner of a 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
  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);
I would like to verify a certain NFT, which I used 0x50f5474724e0ee42d9a4e711ccfb275809fd6d4a (a SANDBOX land contract). 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
let contract = web3.eth.contract(minABI).at(tokenAddress);
contract.ownerOf('18429');
it returns nothing. Can someone 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With