[Ethereum] Web3.js calling ERC721 contract methods

erc-721methodweb3js

I'm writing a React app that calls to see who the owner of a tokenId is.

I am trying to call the built-in function ownerOf(uint256 tokenId) from the ERC721 contract.

Here is my javascript code:

const GetOwnerOf = async (tokenId) => {
  console.log(`Getting owner of ${tokenId}`);

  const bc = new web3.eth.Contract(bannerContractABI, bannerContractAddress);
  const r = bc.methods.ownerOf(tokenId);

  console.log(r);
  return r;
}

I'm seeing this in my console (Chrome):
enter image description here

I have confirmed that the contract ABI is correct and the contract address is correct.

How do i retrieve the data? The ownerOf function returns an address, how do i view this address?

.

Best Answer

Adding to the previous answer, use await since all the methods are async.

const r = await bc.methods.ownerOf(tokenId).call();
console.log(r);
Related Topic