JavaScript in Blockchain
VilniusJs, May 2018
Jaro Šatkevič - @chompomonim
Agenda
- What is Blockchain?
- Which blockchains actually works.
- Intro into Bitcoin and Ethereum.
- Ideas where JavaScript is good choice.
- Short libraries examples.
- What's dApps and where everything is going?
What is blockchain?
Consensus
Programable money
Which of them actually works?
Which of them actually works?
Rest are mostly experiments or tokens
- EOS - ERC20 token
- Cardano - still in early beta
- IOTA - early beta
- Tron - ERC20 token
- ...
Main parts of Bitcoin
Full node
Mining
Wallet
Bitcoin core
Full node
Ledger of transactions
Mining
creation of blocks with tx
Wallet
view balances, create & sign tx
UTXO based balance
In one minute
It knows only what it was told about
Online
Service
User
Oracle Service
Oracles everywhere
- Full nodes
- Mining software
- Wallets of all kinds
- Smart contracts
- Oracles
- Blockchain explorers
- Blockchain monitoring
- Payment processors
- Exchanges (centralised / decentralised)
- Lightning network
- Side chains
- Node infrastructure
- IoT and payments
- Gambling and games
- ...
Is JavaScript good for Blockchain?
Isn't C++, Go, Rust or Java mostly used for blockchain creation?
Yes
Especially for wallets and oracles
JS in Bitcoin
JavaScript libs and tools
Wallets
Libraries
Let's generate address
const bitcoin = require('bitcoinjs-lib')
const hash = bitcoin.crypto.sha256(
Buffer.from('correct horse battery staple')
)
const d = bigi.fromBuffer(hash)
const keyPair = new bitcoin.ECPair(d)
const address = keyPair.getAddress()
console.log(address) //1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8
JS in Ethereum
JavaScript libs and tools
Smart-contracts and Oracles
Libraries
Wallets
contract Auction {
address public beneficiary;
uint256 public auction_start;
uint256 public auction_end;
address public highest_bidder;
uint256 public highest_bid;
bool public ended;
constructor(address _beneficiary, uint256 _bidding_time) public {
beneficiary = _beneficiary;
auction_start = block.timestamp;
auction_end = auction_start + _bidding_time;
}
function bid() payable public {
require(block.timestamp < auction_end);
require(msg.value > highest_bid);
if (highest_bid != 0) {
send(highest_bidder, highest_bid);
}
highest_bidder = msg.sender;
highest_bid = msg.value;
}
function end_auction() public {
require(block.timestamp >= auction_end);
ended = true;
send(beneficiary, highest_bid);
}
}
Oracle
import Web3 from 'web3'
const web3 = new Web3(Web3.givenProvider || "ws://localhost:8546")
const contractAddress = '0x49aC4508A3B125f08d98c6D1564aE88114e4199F'
const contract = new web3.eth.Contract(contractABI, contractAddress, {})
export async function bid(amount) {
return await contract.methods.bid().send({value: amount})
}
export async function showHighestBid() {
return await contract.methods.highest_bid().call()
}
Blockchain ecosystem needs you
Bonus
what's dApps?
Crypto currencies are:
Programmable money
Payment channels and cheques are future!
Let's discuss
Jaro Šatkevič - @chompomonim - me@jarocoin.com
JavaScript in Blockchain
By Jaro
JavaScript in Blockchain
- 2,264