
Ethereum, tokens & smart contracts.
Notes on getting started Part 2. web3.js
So once you have a wallet, are on a test net and have some ether ( read part 1. if any of this is not clear ) where to go next ?
Let’s start coding, web3.js and Solidity seem to be the entry points for interacting with the blockchain programmatically and making contracts & tokens, web3.js I think is a nice prequel to working with solidity, so let’s check it out first:
web3.js :
web3.js is the javascript API for interacting with the Ethereum blockchain, the easiest way to explain it is through a couple of basic examples. A cool and simple way to test some basic commands is via the parity/web3 console:

Let’s start by requesting my balance:
web3.eth.getBalance("0x001301AD1556fD419Cf8970B174fE9AF34267eB8")// 3000000000000000000
Importantly the balance is displayed in wei, not ether, but conveniently there is a function in the api that converts to ether (or other denominations)
web3.fromWei(web3.eth.getBalance("0x001301AD1556fD419Cf8970B174fE9AF34267eB8"), 'ether')// 3
Speaking of denominations, here they are in ether:
| wei | 0.000000000000000001
| kwei - ada | 0.000000000000001
| mwei - babbage | 0.000000000001
| gwei -shannon | 0.000000001
| szabo | 0.000001
| finney | 0.001
| ether | 1
| kether-grand-einstein | 1000
| mether | 1,000,000
| gether | 1,000,000,000
| tether | 1,000,000,000,000
And in wei:
| wei | 1
| kwei - ada | 1,000
| mwei - babbage | 1,000,000
| gwei -shannon | 1,000,000,000
| szabo | 1,000,000,000,000
| finney | 1,000,000,000,000,000
| ether | 1,000,000,000,000,000,000
| kether-grand-einstein | 1,000,000,000,000,000,000,000
| mether | 1,000,000,000,000,000,000,000,000
| gether | 1,000,000,000,000,000,000,000,000,000
| tether | 1,000,000,000,000,000,000,000,000,000,000
Sending ether from one account to another one:
web3.eth.sendTransaction({from:web3.eth.accounts[0], to:web3.eth.accounts[1], value: web3.toWei(1, "ether")})
At this point paritys web3 console crashed my browser 😐 , but upon reloading it presented a confimation/signing screen and the transaction went through !
Besides this I found the console rather limited and running one line commands is probably not ideal anyways, so I chose to move to Atom, node and web3. I spent a few days ! figuring out how to make it work, but finally I got it to run:
- Install Node.js
- Install NPM
- Install web3:
npm install web3@0.20.2NOTE: This drove me crazy, npm at first installed version 1.0.0 and caused issues like not being able to connect and other things, as tooling evolves, be sure to check for the correct versions, in the future you might simply do :npm install web3Also, if you need to see all the versions available you can do so by:npm view web3 versions
- In Atom you have a couple of options for running node. I tried script and atom-runner, they both work fine.
With this setup you can now work within atom and connect to your parity node. ( we’ll try expanding this to work on solidty in the next post ).
- Start and connect parity (to a testnet) :
$ parity --chain kovan// ui is optional at this point
2. In Atom make a file ( test.js ) and start the connection ( I am just asking for my accounts right now ):
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
console.log(web3.eth.accounts);3. Use Atom runner or script to run it, you should get:// [ '0x001301ad1556fd419cf8970b174fe9af34267eb8',
'0x00ce6c92856a657979e7728005dbc9acd002eb09' ]
Let’s now try sending a transaction (we do need the UI when starting Parity for now) :
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));web3.eth.sendTransaction(
{from:web3.eth.accounts[0],
to:web3.eth.accounts[1],
value: web3.toWei(1, "ether")},
function(err, transactionHash) { // Notice the callback.
if (!err)
console.log(transactionHash);
});
My Atom setup in case you were wondering:

Since my wallet is locked, I still need to unlock it via parity on the browser:

And once that is done I get a Transaction Hash ( or Tx) in Atom:
0x9537b1c26a2eeccf5825e8f2ed5698391b3e0dbc5852068fff24789cf91494e6
As mentioned before, you can check transactions ( even on test nets) on a block explorer : https://kovan.etherscan.io/ the above Tx thus would give us :

No Browser:
And how about if we don’t want to use a browser to unlock the wallet ?, you will need to start parity with the personal api enabled:
parity --chain kovan ui --jsonrpc-apis "eth,net,web3,personal"
and in your node.js file use it to unlock your wallet:
var pass = "passphrase";
web3.personal.unlockAccount(web3.eth.coinbase, pass);
web3.eth.sendTransaction({from:web3.eth.accounts[0], to:web3.eth.accounts[1], value: web3.toWei(1, "ether")}, function(err, transactionHash) {
if (!err)
console.log(transactionHash);
});//0x13ce8a96ea3a03a63ad2c5add9c5cec33ac9400bb6ec07bf6e2d7650bc0c6f1f
For other api operations check: https://github.com/paritytech/parity/wiki/JSONRPC
What’s next ?: There is still some ground to cover before issuing smart contracts and tokens, I’ll be going over the basics of Solidity in the next part, but for now we have a basic setup and local development environment for interacting with the ethereum blockchain which should set you on the right path.

Perhaps you like to read these notes in book Form ?If you are looking for an introduction to Ethereum, Solidity and Smart Contracts these notes were edited and content added to work in book form :https://www.amazon.com/dp/B078CQ8L7V
Cheers !
Keno
About the Author :
Born Eugenio Noyola Leon (Keno) I am a Designer,Web Developer/programmer, Artist and Inventor, currently living in Mexico City, you can find me at www.k3no.com