1

hey guys this may be a broad question...

I'm writing a smart contract that recursively builds an svg image given a seed number. the function that draws the image is a view function so it doesn't cost the user any gas, but it recurses a lot so it "costs" A TON of gas for the node executing it (im talking like 100,000,000+ gas) in foundry it works because you can increase the gas limit, but I deployed to sepolia test net and of course it runs out of gas when called from etherscan. do I have any shot at all in getting this to work on a public network? I tried reducing the cost in all the ways I know how to, like basic inline assembly, unchecked{} when doing basic math, rewriting in different ways, etc.

I recall hearing somewhere that the common RPC urls like infura and alchemy allow up to the block gas limit for read functions (which i think is 30,000 for mainnet? so nowhere close). are there any other RPC urls that are either paid or free that allow a higher limit? Or do any layers 2's or sidechains have a higher limit?

My goal is to make this an NFT that raises money for charity. If nothing else works, could I potentially create a node myself, make my own custom RPC url that doesn't have a limit for read functions and then use that for this project? (which I know is technically a centralizing factor). Of course that means it wouldn't work on open sea or any other marketplace, only through a designated front end that i would build.

If i go that route though, couldn't my custom url be attacked? Since there's no gas limit someone could make a function that never stops thus making it useless? Or could I make the url such that it only accepts calls from my specific contract?

so theres a lot of parts to this question, but i hope I explained the gist of it well. if any of it makes sense to you and you have any thoughts I'd love to hear them! if there a gas golfing expert who wants a challenge and/or want to collab on a public goods project shoot me a message!

7
  • 1
    I'd write the equivalent function in javascript to be executed off-chain after reading the initial state from the contract. Not everything has to be executed in a smart contract.
    – Ismael
    Mar 20 at 6:28
  • You can implement the generation using in-svg js, and return such svg if you want all the data to be returned from the smart contract. You will need to just place your parameters inside the returning text
    – FLCL
    Mar 20 at 8:46
  • @Ismael true, but the idea is that a users address is used as a seed to generate a unique image, and it changes over time using block.timestamp, so it does need to be generated on chain i think, right? Mar 20 at 15:56
  • @NolanJannotta When executing a view function off-chain the timestamp is from the last block. To execute a function outside a transaction it is the same if it is written in solidity, javascript, c++, or webassembly.
    – Ismael
    Mar 20 at 19:41
  • @Ismael do you mean calling the smart contract only to get the timestamp and user seed and then generating the image off chain? Mar 21 at 3:04

1 Answer 1

0

Increasing the gas limit for read functions will allow more data to be processed in each transaction, which can increase transaction speed and reduce overall costs.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 24 at 1:12

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.