Blockchain com JavaScript

Fff7258836f20ea66b061b49a51fe8dd?s=47 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.

Fff7258836f20ea66b061b49a51fe8dd?s=128

Beto Muniz

November 24, 2018
Tweet

Transcript

  1. 5.
  2. 6.

    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
  3. 7.
  4. 8.
  5. 16.

    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
  6. 17.
  7. 19.

    É um banco de dados distribuído com uma lista (chain)

    de registros (blocks) interligados e seguros (linked hashes)
  8. 23.

    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
  9. 24.
  10. 26.
  11. 29.
  12. 41.
  13. 42.

    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
  14. 46.
  15. 47.
  16. 48.
  17. 49.
  18. 50.
  19. 51.
  20. 53.

    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
  21. 54.

    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
  22. 56.
  23. 60.

    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; } }
  24. 61.

    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
  25. 67.

    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 })
  26. 68.

    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 })
  27. 69.

    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 })
  28. 70.

    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 })
  29. 71.

    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 })
  30. 72.
  31. 79.

    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());
  32. 80.

    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());
  33. 83.
  34. 84.

    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
  35. 85.

    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
  36. 86.
  37. 87.