How to rectify this error "TypeError: EthereumTransaction is not a constructor"?

700 Views Asked by At

How do I rectify this type error? This is the code for making a transaction and the error received at the terminal is also added.

var transaction = new EthereumTransaction(rawTransaction)

^TypeError: EthereumTransaction is not a constructor

Here is my code:

   var privateKeySender = '*************************************'
   var privateKeySenderHex = new Buffer(privateKeySender, 'hex')
   var transaction = new EthereumTransaction(rawTransaction)
   transaction.sign(privateKeySenderHex)


   $ node index.js
   C:\Users\asus\Desktop\projectFolder\index.js:43
   var transaction = new EthereumTransaction(rawTransaction)
                  ^
     TypeError: EthereumTransaction is not a constructor
     at Object.<anonymous> (C:\Users\asus\Desktop\projectFolder\index.js:43:19)
     at Module._compile (internal/modules/cjs/loader.js:778:30)
     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789: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:831:12)
     at startup (internal/bootstrap/node.js:283:19)
     at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
1

There are 1 best solutions below

0
code-assassin On

The Ethereumjs api has been updated. Do the following instead

var privateKeySender = '*************************************'
var privateKeySenderHex = new Buffer(privateKeySender, 'hex')
var transaction = new EthereumTransaction.Transaction(rawTransaction)
transaction.sign(privateKeySenderHex)