I am having some trouble determining the owner of a specific token_id.

const fs = require('fs');

var jsonFile = "abi/ERC721.abi";
var abi = JSON.parse(fs.readFileSync(jsonFile));

const contractAddress = "<ERC721_address>";
const controller = new web3.eth.Contract(abi, contractAddress);
const tokenId = web3.utils.keccak256(web3.utils.asciiToHex(<Thing>)); // On-chain contract, computes token_id as keccak(bytes("<Thing>"))
console.log(controller.methods.ownerOf(token_id).call()) // Error: Returned error: execution reverted

When I run this code, I keep getting an error. Now, I am quite certain that this is happening because the contract doesn't like the data I am passing to the ownerOf function, but I can't for the life of me figure out why.

Any help much appreciated.


Please inspect your tokenId.

Currently, you are using the output of web3.utils.keccak256 which is a String.

But the input of ...ownerOf is expecting an integer (i.e. a BN).

To convert from the former to the latter, please try web3.utils.toBN.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.