Slide 1

Slide 1 text

Blockchain com JavaScript

Slide 2

Slide 2 text

Sou Beto Muniz @obetomuniz

Slide 3

Slide 3 text

Sou Beto Muniz @obetomuniz minasdev.org

Slide 4

Slide 4 text

Sou Beto Muniz @obetomuniz https://developers.google.com/experts/people/beto-muniz

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Blockchain “Cadeia de Blocos”

Slide 10

Slide 10 text

História do Blockchain

Slide 11

Slide 11 text

2008 O conceito é publicado por Satoshi Nakamoto

Slide 12

Slide 12 text

2009 Começa a blockchain Bitcoin

Slide 13

Slide 13 text

2014 Surge o termo “Blockchain 2.0”

Slide 14

Slide 14 text

2015 Surge a blockchain Ethereum Criada por Vitalik Buterin

Slide 15

Slide 15 text

2016 +1 bilhão de dólares investidos https://www.businessinsider.com/blockchain-technology-is-already-a-1-billion-dollar-industry-and-its-just-the-beginning-2016-6

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

2019 ???

Slide 18

Slide 18 text

Conceito Blockchain

Slide 19

Slide 19 text

É um banco de dados distribuído com uma lista (chain) de registros (blocks) interligados e seguros (linked hashes)

Slide 20

Slide 20 text

Linked Hashes?!

Slide 21

Slide 21 text

Crypto Hashes.

Slide 22

Slide 22 text

E como funciona?

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Mas então como aprender Blockchain?

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

A natureza da conceito blockchain não é linear E na prática…

Slide 28

Slide 28 text

Composição de conceitos

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Bitcoin blockchain Hashing Criptografia P2P Network Nodes Moeda Digital Proof of Work Imutabilidade

Slide 31

Slide 31 text

Ethereum blockchain Smart Contracts Criptografia ÐApps Turing Completude Tokens Proof of Steak Imutabilidade

Slide 32

Slide 32 text

Blockchain NÃO é o Bitcoin Bitcoin É um caso de uso do conceito blockchain

Slide 33

Slide 33 text

BlockchainS “CadeiaS de Blocos”

Slide 34

Slide 34 text

https://votolegal.com.br Justiça Eleitoral

Slide 35

Slide 35 text

https://www.techrepublic.com/article/ibm-taps-blockchain-to-combat-food-contamination-in-global-supply-chain Logística

Slide 36

Slide 36 text

https://www.techrepublic.com/article/why-blockchain-could-be-your-next-form-of-id-as-a-world-citizen Crises Humanitárias

Slide 37

Slide 37 text

https://techcrunch.com/2017/04/26/spotify-acquires-blockchain-startup-mediachain-to-solve-musics-attribution-problem Música e Streaming

Slide 38

Slide 38 text

https://www.criptomoedasfacil.com/odebrechet-cria-ferramenta-blockchain-para-monitorar-licitacoes-em-acordo-com-o-ministerio-publico-federal Anti-Corrupção Política

Slide 39

Slide 39 text

https://www.bndes.gov.br/wps/portal/site/home/imprensa/noticias/conteudo/bndes-lanca-consulta-publica-em-busca-de-componentes-blockchain-para-o-bndestoken Gestão Pública

Slide 40

Slide 40 text

https://www.iota.org/get-started/what-is-iota Internet das Coisas

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

Como Aplicar?!

Slide 44

Slide 44 text

JavaScript

Slide 45

Slide 45 text

História do JavaScript

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

JAVASCRIPT EVERYWHERE

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

2019 2020, 2021, …

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

JavaScript + Blockchain

Slide 58

Slide 58 text

Ethereum “com” JavaScript https://www.ethereum.org

Slide 59

Slide 59 text

Smart Contracts https://www.ethereum.org

Slide 60

Slide 60 text

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; } }

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

ÐApps Aplicações Descentralizadas https://www.ethereum.org

Slide 63

Slide 63 text

Centralizadas Ponto de Falha Único https://www.ethereum.org

Slide 64

Slide 64 text

Distribuídas Micro Services Centralizadas Ponto de Falha Único https://www.ethereum.org

Slide 65

Slide 65 text

Distribuídas Micro Services Descentralizadas Blockchains Centralizadas Ponto de Falha Único https://www.ethereum.org

Slide 66

Slide 66 text

web3.js Ethereum JavaScript API https://github.com/ethereum/web3.js

Slide 67

Slide 67 text

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 })

Slide 68

Slide 68 text

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 })

Slide 69

Slide 69 text

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 })

Slide 70

Slide 70 text

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 })

Slide 71

Slide 71 text

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 })

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

Ark com JavaScript https://ark.io

Slide 74

Slide 74 text

https://ark.io Ark com JavaScript, PHP, Swift, Go, .NET, Python, Java, …

Slide 75

Slide 75 text

ark-js Ark Blockchain Client https://github.com/ArkEcosystem/ark-js

Slide 76

Slide 76 text

https://marketplace.arkaces.com/dashboard

Slide 77

Slide 77 text

Hyperledger com JavaScript https://www.hyperledger.org

Slide 78

Slide 78 text

Chaincode https://www.hyperledger.org

Slide 79

Slide 79 text

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());

Slide 80

Slide 80 text

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());

Slide 81

Slide 81 text

Lisk 100% JavaScript

Slide 82

Slide 82 text

https://blog.github.com/2018-11-15-state-of-the-octoverse-top-programming-languages | https://insights.stackoverflow.com/survey/2018

Slide 83

Slide 83 text

Sidechain

Slide 84

Slide 84 text

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

Slide 85

Slide 85 text

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

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

Obrigado! @obetomuniz