JSFiddle - React, Tailwind, and code Playground
by Lena R
HTML
<button class = "button">Send Transaction</button>
JavaScript
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://136.243.173.186:8540'));
var senderAccount = '0x55aC1a6FE6Dbaf35217a1f2E44C564C5e7B36408';
var senderPrivateKey = 'd2911e2930fb6b7d506badba639b245360690ad3afe66b15f9137ce53e2ce40f';
var amount = parseInt(web3.toWei(0.1, "ether"));
var gasLimit = web3.toHex(53004);
var privateKeyHex = new Buffer(senderPrivateKey, 'hex');
var gasPrice = parseInt(web3.eth.gasPrice);
var gasPriceHex = web3.toHex(gasPrice);
var nonce = web3.eth.getTransactionCount(senderAccount);
var nonceHex = web3.toHex(nonce);
document.querySelector('button').addEventListener('click', function() {
var recacc = document.getElementById("recacc");
const rawTx = {
nonce: nonceHex,
gasPrice: gasPriceHex,
gasLimit: gasLimit,
to: web3.toHex(recacc.value),
value: web3.toHex(amount),
data: '0x00',
chainId: web3.toHex(web3.version.network)
};
var tx = new EthTx(rawTx);
tx.sign(privateKeyHex);
var serializedTx = tx.serialize();
web3.eth.sendRawTransaction("0x" + serializedTx.toString('hex'), function(error, transactionHash) {
if (!error)
console.log("Transaction has been succesfully SENT, transaction hash: ", transactionHash);
else
console.log(error)
})
}, false);