0

In my solidity contract, the function for tokenURI looks like this:

function tokenURI(uint256 tokenId)
  public
  view
  virtual
  override
  returns (string memory)
{
  require(
    _exists(tokenId),
    "ERC721Metadata: URI query for nonexistent token"
  );
  
  if (revealed == false) {
    return string(notRevealedUri);
  }

  string memory currentBaseURI = _baseURI();
  return
    bytes(currentBaseURI).length > 0
    ? string(
      abi.encodePacked(
        currentBaseURI,
        tokenId.toString(),
        baseExtension
      )
    )
  : "";
}

Notice that I have a bool to determine whether or not the "revealed" tokenURI has been set. The problem I've having is when revealed is set to false but I have called the setNotRevealedURI function to actually set the notRevealedUri to a value. I want the function tokenURI to give me this notRevealedUri string but instead it gives me a Promise:

> token.tokenURI(1);
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 501,
  [Symbol(trigger_async_id_symbol)]: 7,
  [Symbol(destroyed)]: { destroyed: false }
}
> 

I've been interacting with the contract using hardhat btw.

So how do I get this function to output a string?

1 Answer 1

1

All contract interactions are asynchronous, you will need to use await or then.

await token.tokenURI(1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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