I ran raw_tx_demo.js, an example code on page 119 of "Mastering Ethereum" by Antonopoulos and Wood, but got an error message below:

$ node raw_tx_demo.js
tx = new ethTx(txData);

TypeError: ethTx is not a constructor
    at Object.<anonymous> (/Users/gemcutter/raw_tx_demo.js:22:6)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

The original source code is in the link below: https://github.com/ethereumbook/ethereumbook/blob/develop/code/web3js/raw_tx/raw_tx_demo.js

I simply copied, pasted it and executed the node command. Could anyone let me know why this happens and how to fix this?

  • 1
    Which version of ethereumjs-tx are you using? The code you pointed at seems to be using 1.x, but the latest version is 2.x. In newer versions, the usage has changed slightly. If that's the issue, you can take a look at the example code here to see what to do: github.com/ethereumjs/ethereumjs-tx. – user19510 Jul 2 '19 at 2:31
  • Brilliant! I followed the instruction at the link you pointed and it worked! Thank you! – Gem Cutter Jul 2 '19 at 3:52

Your Answer

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

Browse other questions tagged or ask your own question.