VilniusJs, May 2018
Jaro Šatkevič - @chompomonim
Full node
Mining
Wallet
Bitcoin core
It knows only what it was told about
Online
Service
User
Oracle Service
Wallets
Libraries
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
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);
}
}
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()
}
Jaro Šatkevič - @chompomonim - me@jarocoin.com