Here's my code for signing nd sending a transaction on Ropsten testnet which is working properly. However, the value that is set to '1' eth is not transferred to the target address.

var Tx = require('ethereumjs-tx').Transaction

const Web3 = require ('web3')
const web3 = new Web3('MY URL including the key')
//Public keys for two accounts
const account1 = '0x8dAd70D461d01C2945A0a1b358eDF21544E03d07'
const account2 = '0x2bA9D4119A2F5c80812d273F3720347dd529FD0A'

const prKey1 = Buffer.from(process.env.PR_KEY1.substring(2,66), 'hex')
const prKey2 = Buffer.from(process.env.PR_KEY2.substring(2,66), 'hex')

// *********************Transfer from account 1 to account 2 *******************
web3.eth.getTransactionCount(account1, (err, txCount) => {
// Build the transaction
    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('100' , 'gwei')) 

// Sign the transaction - choose ropsten as the network
    const tx = new Tx(txObject, {chain: 'ropsten'})
    const serializedTransaction = tx.serialize()
    const raw = '0x' + serializedTransaction.toString('hex')

// Broadcast the transaction 
    web3.eth.sendSignedTransaction(raw, (err, txHash) => {
        console.log('txHash:', txHash)

enter image description here


Change parameter Value in object txObject to value ( without capital letter ). Silly mistake, but happens a lot :)

  • Such embarrassment. It completely exposed me as a beginner :)) Thanks for your help dude
    – Armin
    Sep 23 '20 at 13:47

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.