Skip to content

Instantly share code, notes, and snippets.

@MicrowaveDev
Last active August 25, 2018 21:50
Show Gist options
  • Save MicrowaveDev/9b43f7f9960b8618a80ad0313c4274e7 to your computer and use it in GitHub Desktop.
Save MicrowaveDev/9b43f7f9960b8618a80ad0313c4274e7 to your computer and use it in GitHub Desktop.
// Its your address with some Ethereum balance
const fromAddress = '0x062c6ebe692d0E31B79Eff9532F835bF0dbc1f45';
// Its your friend's wallet address
const toAddress = '0x6122a161c39907502B8BB4636215374389B95c6f';
// Its amount of eth, which you want to send to friend
const ethAmount = 0.01;
// Convert it to wei https://etherconverter.online/
const weiAmount = ethAmount * (10 ** 18);
// Ethereum node, where do you send the transaction
const rpcServer = 'http://127.0.0.1:8545';
const Web3 = require("web3");
const web3 = new Web3(new Web3.providers.HttpProvider(rpcServer));
web3.eth.getGasPrice().then(async (gasPrice) => {
gasPrice = parseInt(gasPrice) || '1000000000';
web3.eth.sendTransaction({
from: fromAddress,
gas: 21000,
gasPrice: gasPrice,
to: toAddress,
value: weiAmount
})
.then(function (receipt) {
console.log(receipt); // {transactionHash: ...}
})
.catch(function (err) {
console.log('err', err);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment