Image for post
Image for post

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 ?

web3.js :

Docs

Image for post
Image for post
web3.eth.getBalance("0x001301AD1556fD419Cf8970B174fE9AF34267eB8")// 3000000000000000000
web3.fromWei(web3.eth.getBalance("0x001301AD1556fD419Cf8970B174fE9AF34267eB8"), 'ether')// 3
| 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
| 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
web3.eth.sendTransaction({from:web3.eth.accounts[0], to:web3.eth.accounts[1], value: web3.toWei(1, "ether")})
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
$ parity --chain kovan// ui is optional at this point
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' ]
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);
});
Image for post
Image for post
Image for post
Image for post
0x9537b1c26a2eeccf5825e8f2ed5698391b3e0dbc5852068fff24789cf91494e6
Image for post
Image for post

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"
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
Image for post
Image for post

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

Written by

AI, Software Developer, Designer : www.k3no.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store