4

I'm trying to deploy a contract into ethereum, but I keep getting "out of gas" error.

How can I know in advance how much ethers I need to deploy a contract?

7
  • 1
    Duplicate and answered here: ethereum.stackexchange.com/questions/799/… Apr 12, 2017 at 11:42
  • Out of gas may be a manifestation of a constructor failure. If there are any required arguments or some other reason the constructor could fail or possibly invalid ByteCode, the error might bubble up and present as out of gas. Maybe post the source to see if someone can spot a problem. Apr 12, 2017 at 12:00
  • It doesn't really answer my question, there is this spreadsheet in that answer that only mentions low level programming, how can I estimate my code based on that? Is there any tool that can pre calculate the cost or something?
    – Resten
    Apr 12, 2017 at 12:00
  • @Rob there is no tool out there to calculate this?
    – Resten
    Apr 12, 2017 at 12:01
  • 1
    @DakotaQuint What Tjaden said, or drop the source code into Remix and see what it estimates. Either will work. In any case, out-of-gas may be misleading. If there is a problem with the contract deployment then no amount of gas will suffice, so pointing this out for you. Not trying to confuse the issue. Apr 12, 2017 at 13:20

1 Answer 1

6

One online tool (no syncing, no installing) is Remix a.k.a. Browser Solidity.

https://ethereum.github.io/browser-solidity

In screen shot below, a trivial contract called "Mortal" cost 319,273 gas to deploy.

enter image description here

Hope it helps.

3
  • But my contract includes other small contract, and other contracts that I have installed through npm. Looks like Remix doesn't useful in this case.
    – hqt
    Apr 28, 2018 at 21:41
  • Thanks @Rob This is helpful. How can we do this programatically?
    – Tomiwa
    May 26, 2022 at 17:26
  • There are several platforms you might use. Hardhat is purpose-built for testing and deploying contracts. There's also truffle. Both let you script out deployment processes in JavaScript. (Over-simplifying) npx hardhat deploy --network kovan May 27, 2022 at 15:50

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.