ethereumjs / ethereumjs-tx

Project is in active development and has been moved to the EthereumJS VM monorepo.
https://github.com/ethereumjs/ethereumjs-vm/tree/master/packages/tx
Mozilla Public License 2.0
781 stars 236 forks source link

I can't see my hash value #161

Closed furkandemireleng closed 5 years ago

furkandemireleng commented 5 years ago

Hello I just interested in Ethereumjs and I try to make a transaction with my app.js file Actually I just follow a tutorial on YouTube but the version changed . I also looked the documentation of EthereumJs but I still have problems . Anyone can help me ?

Here's my code :

var Tx = require('ethereumjs-tx').Transaction 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'

// my first private key for ropsten //17CA41C7C79B1138D2E825A4044675379F117158D1BA0E7F28C98C25D988A319 //my second private key for ropsten //966DB6B3BDDBA4D7539EEF98073E135F01524A6746A89ED965F2FACB271FD336

const private_Key_1 = Buffer.from('17CA41C7C79B1138D2E825A4044675379F117158D1BA0E7F28C98C25D988A319','hex') //const private_Key_2 = new Buffer('966DB6B3BDDBA4D7539EEF98073E135F01524A6746A89ED965F2FACB271FD336','hex') //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')), } console.log(txObject) //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')

//3 broadcast the transaction to ropsten
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'))})

and results like :

account 2 balance : 3 account 1 balance : 17.99979 { nonce: '0x1', to: '0x0995a5Db39dB3C9a81aECEA661CE63AeDc7aB8eF', value: '0xde0b6b3a7640000', gasLimit: '0x5208', gasPrice: '0x2540be400' } txHash : null

why my txHash returns null ?

furkandemireleng commented 5 years ago

I fix it because I can't connect the Ropsten test network.

alcuadrado commented 5 years ago

I'm closing this issue, as @furkandemireleng said it's already fixed.

BTW, @furkandemireleng note that web3.js is a separate project.