Loading...
App.js
var Tx = require('ethereumjs-tx').Transaction;
const Web3 = require('web3');
var url = 'https://kovan.infura.io/v3/1988f993df8140259d2198f3f33f3012'
const web3 = new Web3(url);
//Get an account address and it's private key
const account1 = '0xE6c5329453F4C650716B2dc04283A73e381c8750';
const privateKey1 = Buffer.from("a6d49d470bb92210fbefaa8f3037ca0b4e67806f0997dd4d75f5b25b7285d788",'hex');
//Get another account address and it's private key
const account2 = '0xDCAB519AD714639B6E911C179F3f25344ED93193';
const privateKey2 = Buffer.from("02795c427f76f5a7346b96c73c6e373256c7aed620c9da2125a03a5b78140101web3",'hex');
//'Buffer.from' converts string to binary data and we changed then to type hex
web3.eth.getTransactionCount(account1, (err, txCount) => {
//since we need txCount to use in building transaction
//so we defined it here
//Build the Transaction\\
const txObject = {
nonce: web3.utils.toHex(txCount),
to: account2 ,
value: web3.utils.toHex(web3.utils.toWei('0.3','ether')),
gasLimit: web3.utils.toHex(21000) ,
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei'))
}
console.log(txObject);
}
)
Above code is preety much self explanatory.
Then run this code from cmd using this code to see the transaction we build
node app
For test ethers and link tokens. Click Here
For many more exciting tutorials keep following my username @BlockTalks_Raj
!!!!!HAPPY LEARNING!!!!