I can't deploy an empty Solidity contract to a local Geth blockchain using either a web3js or ethers.js node.js application. Web3js throws a “contract cannot be stored” exception, ethers.js returns a transaction receipt with status 0x0, getCode returns 0x0, and geth displays the “stack underflow” VM error message. However, I have no trouble deploying the same contract from the Geth console using the same ABI and byte code data generated by the Solidity compiler in the applications.

The only explanation I can think of is that the ABI or bytecode data is corrupted in the JSON-RPC layer between the application and the ethereum node. Has anyone else experienced this problem? Is there any guidance you can give me concerning how to isolate, debug, and fix this?

Except from Web@0.20.1 code: exception thrown on second callback invocation

var theContract = web3.eth.contract ( JSON.parse(compile.interface) ) ;
var transObj = { from: accounts [0] , gas: … , gasPrice: … , data: byteCode } ;

var contractInstance = theContract.new ( transObj , function(err, myContract){
          console.log ( " Inside callback ..... " ) ;
       // NOTE: The callback will fire twice!
       // Once the contract has the transactionHash property set and once its deployed on an address
  • Repeated with code from contract.deploy( ... ) example taken from web3 documentation for version 1.0.0-beta33... same results – Michael E. Rose Apr 27 '18 at 23:47
  • Do you have a transaction id of the failed transaction? Is the byteCode empty? – Ismael Apr 29 '18 at 1:03

The problem was caused by applying the ethers.js utility bytesToHex method to the compiled bytecode instead of simply prepending "0x" .... this caused the Ethereum VM to throw a stack undeflow exception. I want to thank those who responded to my post and close the issue since it has been resolved.


I think you want to use theContract.deploy() instead of theContract.new().

  • I ran the deploy example fom web3js documentation (1.33-beta) and got exactly the same results. – Michael E. Rose Apr 27 '18 at 23:35
  • 1. accounts == web3.eth.accounts, right? Or accounts[0] is a valid account with gas, right? Let me know if I'm wrong. 2. Have you tried a non-empty contract? A stack underflow typically results from missing data. 3. If this is happening with both web3 and ethers, then it might be a problem with geth. You could search geth's issues on github or submit your own issue if necessary. – sfmiller940 Apr 28 '18 at 2:16

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.