Skip to content

Instantly share code, notes, and snippets.

@bitgord
Last active December 3, 2016 19:14
Show Gist options
  • Save bitgord/02a0a463d1878527d5ae16d3661c41b2 to your computer and use it in GitHub Desktop.
Save bitgord/02a0a463d1878527d5ae16d3661c41b2 to your computer and use it in GitHub Desktop.
Eth Transactions
// package.json
{
"dependencies": {
"web3": "0.17.0-alpha",
"ethereumjs-util": "4.5.0",
"ethereumjs-tx": "1.1.2"
}
}
//Goto Node Console
node
//Get Web3 Instance in Node Console
var Web3 = require("web3")
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))
//See Account
web3.eth.accounts[0]
//See Balance in Wei
web3.eth.getBalance(web3.eth.accounts[0])
//See Balance in Ether
web3.fromWei(web3.eth.getBalance(web3.eth.accounts[0]), 'ether')
//See Number
web3.fromWei(web3.eth.getBalance(web3.eth.accounts[0]), 'ether').toNumber()
//Create Account Helper Methods
acct1 = web3.eth.accounts[0]
acct2 = web3.eth.accounts[1]
acct3 = web3.eth.accounts[2]
//Create Balance Method
var balance = (acct) => { return web3.fromWei(web3.eth.getBalance(acct), 'ether').toNumber() }
//Query Balance to Check its Working
balance(acct1)
//Send 1 Ether from acct1 to acct2
web3.eth.sendTransaction({from: acct1, to:acct2, value: web3.toWei(1, 'ether'), gasLimit: 21000, gasPrice: 20000000000})
//Create Variable for TxHash Output
var txHash = _
//Check Tx Went Through
balance(acct2)
balance(acct1)
//Check Transaction Data From txHash
web3.eth.getTransaction(txHash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment