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?

Resten
  • 533
  • 1
  • 8
  • 14
  • 1
    Duplicate and answered here: http://ethereum.stackexchange.com/questions/799/how-much-does-it-cost-to-use-a-contract – Dakota Quint Apr 12 '17 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. – Rob Hitchens Apr 12 '17 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 '17 at 12:00
  • @Rob there is no tool out there to calculate this? – Resten Apr 12 '17 at 12:01
  • The easiest way to tell is to just deploy the contract on testrpc or the testnet and see how much it costs – Tjaden Hess Apr 12 '17 at 12:48
  • Is there any online tool for that? I'm not synced with the network on my pc – Resten Apr 12 '17 at 12:55
  • 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. – Rob Hitchens Apr 12 '17 at 13:20

1 Answers1

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.

Rob Hitchens
  • 55,151
  • 11
  • 89
  • 145
  • 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 '18 at 21:41
  • Thanks @Rob This is helpful. How can we do this programatically? – Tomiwa May 26 '22 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 – Rob Hitchens May 27 '22 at 15:50