Closed furkandemireleng closed 5 years ago
Hey guys ! I just try to work with Ropsten network
`var Tx = require('ethereumjs-tx') const Web3 = require('web3') const web3 = new Web3('https://ropsten.infura.io/v3/1a9bb467fd9e4f6c809eac78f730f565') //try to make a node //now we try to test network
const account1 ='0xC41F7b463afA880CFda9A07a7713fC052984191C' const account2 = '0x0995a5Db39dB3C9a81aECEA661CE63AeDc7aB8eF'
const private_Key_1 = 'I hide my private key' const private_Key_2 = 'I hide my second private key to' //1 build transaction web3.eth.getTransactionCount(account1, (err,txCount) => { const txObject ={ nonce: web3.utils.toHex(txCount), to: account2, value: web3.utils.toHex(web3.utils.toWei('1','ether')), gasLimit: web3.utils.toHex(21000), gasPrice: web3.utils.toHex(web3.utils.toWei('10','gwei')), } //2 sign transaction with my private key const tx = new Tx(txObject) tx.sign(private_Key_1)
const serializedTransaction =tx.serialize() const raw ='0x'+serializedTransaction.toString('hex') web3.eth.sendSignedTransaction(raw, (err,txHash) => { console.log('txHash : ',txHash) })
})
web3.eth.getBalance(account1, (err,bal) => { console.log('account 1 balance :' , web3.utils.fromWei(bal, 'ether'))}) web3.eth.getBalance(account2, (err,bal) => { console.log('account 2 balance :' , web3.utils.fromWei(bal, 'ether'))})
//3 broadcast the transaction to `ropsten``
but my code get a error : (node:2535) UnhandledPromiseRejectionWarning: TypeError: Tx is not a constructor
can you help me please ?
var Tx = require('ethereumjs-tx')
This should be replaced for var Tx = require("ethereumjs-tx").Transaction.
var Tx = require("ethereumjs-tx").Transaction
Thanks it works !
Thanks it works 2
Hey guys ! I just try to work with Ropsten network
`var Tx = require('ethereumjs-tx') const Web3 = require('web3') const web3 = new Web3('https://ropsten.infura.io/v3/1a9bb467fd9e4f6c809eac78f730f565') //try to make a node //now we try to test network
const account1 ='0xC41F7b463afA880CFda9A07a7713fC052984191C' const account2 = '0x0995a5Db39dB3C9a81aECEA661CE63AeDc7aB8eF'
const private_Key_1 = 'I hide my private key' const private_Key_2 = 'I hide my second private key to' //1 build transaction web3.eth.getTransactionCount(account1, (err,txCount) => { const txObject ={ nonce: web3.utils.toHex(txCount), to: account2, value: web3.utils.toHex(web3.utils.toWei('1','ether')), gasLimit: web3.utils.toHex(21000), gasPrice: web3.utils.toHex(web3.utils.toWei('10','gwei')), } //2 sign transaction with my private key const tx = new Tx(txObject) tx.sign(private_Key_1)
})
web3.eth.getBalance(account1, (err,bal) => { console.log('account 1 balance :' , web3.utils.fromWei(bal, 'ether'))}) web3.eth.getBalance(account2, (err,bal) => { console.log('account 2 balance :' , web3.utils.fromWei(bal, 'ether'))})
//3 broadcast the transaction to `ropsten``
but my code get a error : (node:2535) UnhandledPromiseRejectionWarning: TypeError: Tx is not a constructor
can you help me please ?