My contract is reaching beyond the gas limit and I cannot deploy it on the main net as is. I can reduce the gas cost by removing all the constant functions whose only purpose it to give access to the underlying data in a nice way.

This actually reduce the gas cost by more than 30 % and should allow me to deploy my contract on the mainnet.

Since that raw data is theoretically accessible anyway. I was wondering if there is a nice way to replicate such constant functions on the web3 / js side ?

By the way, I know that I could break my contract in several sub contract via DELEGATECALL. But I am here specifically interested in the ability to reduce gas cost by removing the need of constant functions.

2 Answers 2


You can use web3.eth.getStorageAt() to get the storage at a specific position. I can't give an example, because I've personally never used it. You'll have to figure out which storage position you'll need to look at, probably from this page.

I'd caution against removing constant functions, because even if you can use web3.js to get at the data anyway, it'll be impossible for other contracts to do so. Splitting contracts is probably the way to go. Libraries are remarkably easy to use, even if it takes additional steps to deploy.

  • Thanks for the info. For my use case, no other contract will need access and thus these constant functions are just dead code from the blockchain execution side. On top of that using Libraries just for that make the code harder to read and reason about it
    – wighawag
    Nov 13, 2016 at 12:39

Just as I was posting the question, I remembered seeing some EIP on something along these line. I found it back here : https://github.com/ethereum/EIPs/issues/144

It would basically allow web3 client to submit snipset of code (evm byte code or even solidity code) to a node and request execution.

This would solve my use case but this is not available yet

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.