1

So this question seems trivial but I can't find any comprehensive answer, though reading through:

My question is as follows:

  • I can call estimateGas to estimate the gas needed to call one of my functions from ethers.js
  • What is the limit gas for my function?

Context: I am working on a on-chain NFT project and the tokenURI method is a bit complex. I don't understand if this is a problem. And how much gas maximum it should have?

1 Answer 1

3

What is the limit gas for my function?

estimateGas will return a reasonably accurate value for your tokenURI method.

(If your tokenURI method is very contrived/variable, be aware of What are the limitations to estimateGas and when would its estimate be considerably wrong?)


tokenURI method is a bit complex. I don't understand if this is a problem.

Users generally do not invoke the tokenURI method so you are usually OK.

The effect of any expensive smart contract function (including tokenURI) is less on-chain composability/interoperability with that function, possibly the whole contract.

A web2 analogy might be calling a slow, unreliable, or paid API: developers will avoid calling those APIs in preference for something faster and reliable.


And how much gas maximum it should have?

We can say that a very expensive tokenURI method would be one that consumes half the block gas limit. Even 10% of the block gas limit seems high, so I would aim for lower than 10%.

Even though tokenURIis usually only called off-chain so that its gas usage doesn't matter as much, I would not underestimate the chances that there may be creative uses of tokenURI on-chain in the future, so I would still try to be reasonable about its gas consumption.

2
  • thanks for your insights. I do understand the point about composability and future uses, but still, would it get rendered on, e.g. OpenSea or etherscan if gas required is "too high", and consequently what would "too high" be. Commented Jan 17, 2022 at 9:54
  • 1
    Don't know what those services use; if they use Geth, the default limit might still be 50M gas. Etherscan and OpenSea also supports testnets so it would be interesting to freely deploy to them and see at what point do things break.
    – eth
    Commented Jan 18, 2022 at 1:23

Your Answer

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

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