Suppose that you deployed a contract, but your transaction got canceled due to an out-of-gas error. Is there any way to re-deploy the contract so that it takes the same address?



A contract address is made by combining the address creating the contract with the nonce of that address. (See here for the specifics, and some interesting tricks you can play with this.) Any transaction that is included in the blockchain increments that nonce, even if it ends with an out-of-gas error. So you can never use the same address+nonce combination again, and that means you'll never have another chance to create the contract at that address.

If this matters to you one thing to consider in future might be creating the contract with another contract. That way the nonce used will be the nonce of the creator contract instead of the address of the transaction that triggers it, and if the contract creation transaction fails, that should revert the whole thing and leave the contract's nonce unaffected. That way you can retry later with more gas and you should get the address you originally expected. (I haven't tried this but logically I think it should work.)

  • Aw that makes sense. Add 0.25 Eth to the unspendable Eth count... sighs – MaiaVictor Mar 24 '17 at 0:56
  • @MaiaVictor Was there a use case why the 0.25 ETH couldn't have been sent using the constructor instead of "prefunding" it? – eth Mar 24 '17 at 1:01
  • @eth no, basically it was 3 AM, I was tired, had to deploy it using MyEtherWallet and wasn't sure how to fund it on deploy with MEW, so I just added a totally not cool function() payable {}, deployed and sent the Ether - only to wake up and realize I didn't have enough gas. Woops! Totally my fault for being imprudent. – MaiaVictor Mar 24 '17 at 1:05
  • @MaiaVictor Thanks, I see it wasn't a case of prefunding. – eth Mar 24 '17 at 1:08
  • @eth I saw your question now. I wonder who you are and why you took that name (: – MaiaVictor Mar 24 '17 at 1:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.