1

I am trying to get the owner of a NFT in solidity & web3 by calling the Contract and the token id

In Web3.js-v1.3.5 I've tried this so far, but the result isn't ever calledBack!

How can I handle this? and how can I write this in solidity as well ?

        var abi_ = [ {
        "constant": true,
        "inputs": [
            {
                "name": "_tokenId",
                "type": "uint256"
            }
        ],
        "name": "ownerOf",
        "outputs": [
            {
                "name": "",
                "type": "address"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    }]

    const smartContractAddress = "0x495f947276749ce646f68ac8c248420045cb7b5e"
    const contract = new web3.eth.Contract(abi_, smartContractAddress)
    let owner = await contract.methods.ownerOf('91338127118827779192862936396890434745733899848224782300810335984505495486465').call()
    //Code never reaches here
    console.log(owner)
1

Try this abi:

 {"constant":true,"inputs":
  [{"internalType":"uint256","name":"tokenId","type":"uint256"}],
 "name":"ownerOf",
 "outputs":[{"internalType":"address","name":"","type":"address"}],
 "payable":false,"stateMutability":"view","type":"function"}

You forgot to put the owner address of the Contract in "from" place:

var myContract = new web3.eth.Contract(abi, '0x495f947276749ce646f68ac8c248420045cb7b5e', {
    from: '0x1234567890123456789012345678901234567891', //<--- here 
    gasPrice: '20000000000' 
});

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.