Last active
December 3, 2016 19:14
Eth Transactions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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