You must have node and npm downloaded on your computer. After this tutorial you should have sent an ethereum transaction with test ether on testrpc, an ethereum blockchain used for testing.

npm install web3 ethereumjs-tx ethereumjs-util

Download web3, ethereumjs-tx and ethereumjs-util from your terminal.

node

Go to your node console.

var Web3 = require("web3")

Require web3.

var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))

Connect to web3 instance in your Node console. 8545 is the default port to connect to.

testrpc

In a new terminal window run testrpc.

web3.eth.getBalance(web3.eth.accounts[0])

Check balance of your first account, account[0], in Wei.

web3.fromWei(web3.eth.getBalance(web3.eth.accounts[0]), 'ether')

Check balance of account[0] in Ether.

acct1 = web3.eth.accounts[0]
acct2 = web3.eth.accounts[1]
acct3 = web3.eth.accounts[2]

Create helper methods that make it easier for you to interact with each account.

var balance = (acct) => { return web3.fromWei(web3.eth.getBalance(acct), 'ether').toNumber()}

Create a method to find the balance of each account.

balance(acct1)

Query balance of account[0] to make sure its working.

web3.eth.sendTransaction({from: acct1, to:acct2, value: web3.toWei(1, 'ether'), gasLimit: 21000, gasPrice: 20000000000})

Send 1 test ether from acct1 to acct2.

var txHash = _

Create variable for txHash output from above.

balance(acct2) balance(acct1)

Query balance of acct1 and acct1 to make sure the transaction went through.

web3.eth.getTransaction(txHash)

Check transaction data from txHash.

Disclaimer: The author is the founder of MLG Blockchain. This tutorial was originally published on MLG Blockchain.

MLG Blockchain is a blockchain development and consulting firm based in Toronto that is focused on building next generation applications using blockchain and smart contract technology. See more blockchain development tutorials on the MLG Blockchain blog.