Skip to content

Instantly share code, notes, and snippets.

@fcgdam
Created August 12, 2020 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcgdam/c2da610a48d2b76b05f634fc1d4ab8c6 to your computer and use it in GitHub Desktop.
Save fcgdam/c2da610a48d2b76b05f634fc1d4ab8c6 to your computer and use it in GitHub Desktop.
Simple Ethereum Ether transaction for Ganache
const Web3 = require('web3');
const provider = new Web3.providers.HttpProvider("http://localhost:7545");
const web3 = new Web3(provider);
/*web3.eth.net.isListening()
.then(() => console.log('web3 is connected'))
.catch(e => console.log('Wow. Something went wrong'));
*/
( async() => {
console.log("Getting Ethereum accounts...");
const accounts = await web3.eth.getAccounts();
console.log("Done");
web3.eth.defaultaccount = accounts[0];
senderAccount = accounts[0];
receiverAccount = accounts[1];
console.log("Sender Account: ", senderAccount );
console.log("Receiver Account: ", receiverAccount );
web3.eth.sendTransaction({
from: senderAccount,
to: receiverAccount,
value: 10000000000000000000
})
.on('error', function(err){
console.log('Error executing transaction: ', err);
})
.on('transactionHash', function(transactionHash){
})
.on('receipt', function(receipt){
var transactionHash = receipt.transactionHash;
console.log('transactionHash', transactionHash);
})
.on('confirmation', function(confirmationNumber, receipt){
console.log("Transaction completed: ", confirmationNumber);
console.log("Transaction receipt: ", receipt );
process.exit(0);
});
})(); // End async()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment