0

I am trying to optimize every last drop of gas I can in my smart contract. One of my functions takes a single decimal number around 1,000,000. First, I just made it a uint256. But I feel like this was wasting a lot of space. I made it a uint32, but this didn’t ultimately change anything and after passing it through the ABI on with web3, the input was still as long.

Is there anyway to shorten the input? Does this even save gas if I ultimately have to convert this number to a uint256 anyway?

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • It's really only going to matter if you're saving the values as part of the contract state. See https://stackoverflow.com/questions/49872713/initialize-a-big-fixed-length-array-in-solidity/49882922#49882922. Same information there applies to contract state which are tightly packed (Also see http://solidity.readthedocs.io/en/v0.4.24/miscellaneous.html#layout-of-state-variables-in-storage) – Adam Kipnis Jun 18 '18 at 02:56
  • You won't be able to save gas in there, can you post your contract, maybe other functions can be optimized. – Marcos Casagrande Jun 18 '18 at 13:35
  • What about if I write with assembly? – user9714804 Jun 20 '18 at 17:25

0 Answers0