Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Blockchain com JavaScript

Beto Muniz
November 24, 2018

Blockchain com JavaScript

Apresentação com exemplos, benefícios e possibilidades da utilização de Blockchain com JavaScript em aplicações reais.

Beto Muniz

November 24, 2018
Tweet

More Decks by Beto Muniz

Other Decks in Technology

Transcript

  1. import SHA256 from "js-sha256" class Block { constructor(index, data, previousHash)

    { this.index = index this.timestamp = new Date() this.data = data this.previousHash = previousHash this.hash = this.calcHash() } calcHash() { const sha = SHA256.create() sha.update(`${this.index}${this.timestamp}${this.data}${this.previousHash}`) return sha.hex() } static generator(block = { index: 0, hash: "0" }, data = "genesis") { return new Block(block.index, data, block.hash) } } https://github.com/openblockchains/awesome-blockchains/blob/master/blockchain.js/blockchain.js
  2. 2018 +1600 criptomoedas +500 bilhões de reais de valor de

    mercado +2000 aplicações descentralizadas na Ethereum https://en.wikipedia.org/wiki/List_of_cryptocurrencies https://coinmarketcap.com | https://www.stateofthedapps.com
  3. É um banco de dados distribuído com uma lista (chain)

    de registros (blocks) interligados e seguros (linked hashes)
  4. Hashing Criptografia P2P Network Nodes Assinaturas Digitais Proof of Steak

    Proof of Authority Turing Completude InterPlanetary File System Consensus Protocols Delegated Proof of Stake Byzantine Fault Tolerance Proof of Work Smart Contracts Sidechains Tokens ÐApps Consortium blockchains
  5. Transparência de dados Governança Descentralizada Performance Segurança Privacidade* Rastreabilidade de

    Informação Imutabilidade Escalabilidade Tokenização Aplicabilidade … Open Source Comunidade Baixo Custo
  6. Aplicações Mobile Nativas Browser Aplicações para SmartTVs Banco de Dados

    Aplicações de Linha de Comando Aplicações Desktop Sistemas Operacionais Blockchain Servidor Games* Progressive Web Apps Internet das Coisas
  7. Utilizada por grandes empresas Ecossistema vasto Multiparadigma Gerada para um

    mundo conectado Fácil de iniciar os estudos Mercado abundante e generoso Melhoria contínua Comunidade vibrante e ativa … Auxilia no aprendizado de outras linguagens Linguagem mais popular do mundo
  8. https://www.ethereum.org/token pragma solidity ^0.4.20; contract HubConToken { mapping (address =>

    uint256) public balanceOf; function HubConToken(uint256 initialSupply) public { balanceOf[msg.sender] = initialSupply; } function transfer(address _to, uint256 _value) public returns (bool success) { require(balanceOf[msg.sender] >= _value); require(balanceOf[_to] + _value >= balanceOf[_to]); balanceOf[msg.sender] -= _value; balanceOf[_to] += _value; return true; } }
  9. https://github.com/s-tikhomirov/smart-contract-languages Vyper Solidity LLL - Lisp* Ethereum bytecode Bamboo eWASM

    - WebAssembly* Serpent - Python* SolidityX Pyramid Flint Yul Babbage Mutan - C* Idris Lolisa L4 Formality Logikon
  10. import web3 from "web3" const ORIGEM = “0xf4e36a1c193e687b459f22d3512dd0cfec289fd3" const DESTINO

    = "0xcc16e3c00dbbe76603fa833ec20a48f786dfe611" const HubConTokenSmartContract = "0xcc16e3c00dbbe76603fa833ec20a48f786dfe610" const HubConTokenABIObject = { ... } const SmartContract = await new web3.eth.Contract( HubConTokenABIObject, HubConTokenSmartContract ) SmartContract.methods.transfer(DESTINO, 1).send({ from: ORIGEM })
  11. import web3 from "web3" const ORIGEM = “0xf4e36a1c193e687b459f22d3512dd0cfec289fd3" const DESTINO

    = "0xcc16e3c00dbbe76603fa833ec20a48f786dfe611" const HubConTokenSmartContract = "0xcc16e3c00dbbe76603fa833ec20a48f786dfe610" const HubConTokenABIObject = { ... } const SmartContract = await new web3.eth.Contract( HubConTokenABIObject, HubConTokenSmartContract ) SmartContract.methods.transfer(DESTINO, 1).send({ from: ORIGEM })
  12. import web3 from "web3" const ORIGEM = “0xf4e36a1c193e687b459f22d3512dd0cfec289fd3" const DESTINO

    = "0xcc16e3c00dbbe76603fa833ec20a48f786dfe611" const HubConTokenSmartContract = "0xcc16e3c00dbbe76603fa833ec20a48f786dfe610" const HubConTokenABIObject = { ... } const SmartContract = await new web3.eth.Contract( HubConTokenABIObject, HubConTokenSmartContract ) SmartContract.methods.transfer(DESTINO, 1).send({ from: ORIGEM })
  13. import web3 from "web3" const ORIGEM = “0xf4e36a1c193e687b459f22d3512dd0cfec289fd3" const DESTINO

    = "0xcc16e3c00dbbe76603fa833ec20a48f786dfe611" const HubConTokenSmartContract = "0xcc16e3c00dbbe76603fa833ec20a48f786dfe610" const HubConTokenABIObject = { ... } const SmartContract = await new web3.eth.Contract( HubConTokenABIObject, HubConTokenSmartContract ) SmartContract.methods.transfer(DESTINO, 1).send({ from: ORIGEM })
  14. import web3 from "web3" const ORIGEM = “0xf4e36a1c193e687b459f22d3512dd0cfec289fd3" const DESTINO

    = "0xcc16e3c00dbbe76603fa833ec20a48f786dfe611" const HubConTokenSmartContract = "0xcc16e3c00dbbe76603fa833ec20a48f786dfe610" const HubConTokenABIObject = { ... } const SmartContract = await new web3.eth.Contract( HubConTokenABIObject, HubConTokenSmartContract ) SmartContract.methods.transfer(DESTINO, 1).send({ from: ORIGEM })
  15. import shim from "fabric-shim"; class Chaincode { Init(stub) { return

    stub .putState("chave", Buffer.from("valor")) .then(() => shim.success(), () => shim.error()); } Invoke(stub) { return stub.getState("chave").then(() => shim.success()); } }; shim.start(new Chaincode());
  16. import shim from "fabric-shim"; class Chaincode { Init(stub) { return

    stub .putState("chave", Buffer.from("valor")) .then(() => shim.success(), () => shim.error()); } Invoke(stub) { return stub.getState("chave").then(() => shim.success()); } }; shim.start(new Chaincode());
  17. const lisk = require('lisk-elements').default; const client = lisk.APIClient.createTestnetAPIClient(); const tx

    = lisk.transaction.transfer({ recipientId: "YOUR LISK ID", passphrase: "YOUR PASSPHRASE HERE", amount: "1", data: "Hello World" }); try { client.transactions.broadcast(tx); } catch(err) { console.log(err.message); } å https://lisk.io/documentation/lisk-elements/packages/api-client
  18. const lisk = require('lisk-elements').default; const client = lisk.APIClient.createTestnetAPIClient(); client.dapps.get({ name:

    'LiskKitties' }) .then(res => { console.log(res.data); }) https://lisk.io/documentation/lisk-elements/packages/api-client