Why do I keep on getting this error when I try to send ether from one of my accounts to the other? Note that when I send it between other accounts the same code works, I have checked the balance and it shows that there is actually sufficient balance. So, what's going on here? When it works it outputs: failed to check for transaction receipt, when it doesn't work it outputs: unhandled promise rejection warning. code:
var Web3 = require('web3')
web3 = new Web3('https://ropsten.infura.io/hqRzEqFKv6IsjRxfVUMH')
const account1 = '0x0539B9c9C886e93778542B553C64cb5EAfB902b1'
const account2 = '0xca7F442c44b079dd07324C9c7eDfe348b92f46c9'
const privatekey1 = Buffer.from('c986afe0XXXXXXXXXXXXXXXXXXXXXXXXXXca1aed18981b' , 'hex')
const privatekey2 = Buffer.from('1311767cXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXb97bbfee1cf7fd2411e2d8' , 'hex')
web3.eth.getTransactionCount(account2 , (err, transCount) => {
const txObject = {
nonce: web3.utils.toHex(transCount) ,
from: account1 ,
to: account2 ,
value: web3.utils.toHex(web3.utils.toWei('0.00001' , 'ether')) ,
gasLimit: web3.utils.toHex(21000) ,
gasPrice: web3.utils.toHex(web3.utils.toWei('10' , 'gwei'))
}
var tx = new Tx(txObject , {chain:'ropsten', hardfork: 'petersburg'})
tx.sign(privatekey1)
const serializedTransaction = tx.serialize()
const raw = '0x' + serializedTransaction.toString('hex')
try{
web3.eth.sendSignedTransaction(raw).on('receipt', console.log)
catch(error) {
console.log(error)
}
})
Command prompt outputs:
C:\Users\HP\Desktop\block chain\js>node broadcastingatransaction (node:4308) UnhandledPromiseRejectionWarning: Error: Failed to check for transaction receipt: {} at Object._fireError (C:\Users\HP\node_modules\web3-utils\src\index.js:57:17) at C:\Users\HP\node_modules\web3-core-method\src\index.js:272:27 (node:4308) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 34) (node:4308) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.