JSFiddle - React, Tailwind, and code Playground
HTML
<button onclick="sendTransaction()">Send Transaction</button>
JavaScript
var web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://xxx.xxx.xxx.xxx:8540'));
var senderAccount = '0x55...1212';
var senderPrivateKey = "";
var receiverAccount = '0x4d...1212';
var amount = parseInt(web3.toWei(0.1, "ether"));
var gasLimit = web3.toHex(35000);
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);
const rawTx = {
nonce: nonceHex,
gasPrice: gasPriceHex,
gasLimit: gasLimit,
to: receiverAccount,
value: web3.toHex(amount),
data: '0x00',
chainId: web3.toHex(web3.version.network)
};
console.log("rawTx", rawTx)
var tx = new EthTx(rawTx);
tx.sign(privateKeyHex);
var serializedTx = tx.serialize();
function sendTransaction() {
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)
});
}