build a scalable dapp with the liquidity javascript sdk
play

Build a scalable dApp with the Liquidity Javascript SDK Guillaume - PowerPoint PPT Presentation

Build a scalable dApp with the Liquidity Javascript SDK Guillaume Felley - BDLT summer school 2019 NOCUST - Outline 1. Introduction 2. Presentation of the NOCUST SDK 3. Exercise NOCUST - Introduction What is it ? The benefits ?


  1. Build a scalable dApp with the Liquidity Javascript SDK Guillaume Felley - BDLT summer school 2019

  2. NOCUST - Outline 1. Introduction 2. Presentation of the NOCUST SDK 3. Exercise

  3. NOCUST - Introduction What is it ? The benefits ? ● Scalable Layer 2 scalability solution ● Free transactions ⛔⛽ ● ● Off-chain transactions (and more) ● Instant ⚡ Commit-chain, non-custodial side-chain ● Private (Upcoming) ● ➡ Secure transactions, off-the-blockchain ● Blockchain agnostique And still trustless.. ● ➡ Better user experience

  4. NOCUST - Introduction The drawbacks ? No smart contracts (transactions and atomic swaps only) ● ● Online presence requirements Architecturally centralised (But non-custodian!) ●

  5. NOCUST - Overview

  6. NOCUST - How does it work ?

  7. NOCUST - Instant finality Insurance pool ● ● Collateral re-usable each round TX can be accepted instantly ●

  8. NOCUST - Account based data structure

  9. NOCUST - Registration ● Ethereum addresses need to register with the commit-chain ● Off-chain (= POST request) ⚠ The recipient of a transaction need to have register to receive funds ●

  10. NOCUST - SDK, hands on ! Doc: http://docs.liquidity.network Github: https://github.com/liquidity-network

  11. NOCUST - Install and setup Install the library from NPM: > npm install nocust-client Install required dependencies: > npm install web3@1.0.0-beta.37 bignumber.js

  12. NOCUST - Choose your hub Ethereum Mainnet NOCUST smart-contract address (contractAddress) 0x83aFD697144408C344ce2271Ce16F33A74b3d98b Hub API URL (hubApiUrl) https://public.liquidity.network/ LQD ERC-20 contract address 0xD29F0b5b3F50b07Fe9a9511F7d86F4f4bAc3f8c4 Rinkeby Testnet NOCUST smart-contract address (contractAddress) 0x66b26B6CeA8557D6d209B33A30D69C11B0993a3a Hub API URL (hubApiUrl) https://rinkeby.liquidity.network/ Test ERC-20 contract address 0xA9F86DD014C001Acd72d5b25831f94FaCfb48717 Limbo test commit-chain NOCUST smart-contract address (contractAddress) 0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7 Hub API URL (hubApiUrl) https://limbo.liquidity.network/ Test ERC-20 contract address 0xe982E462b094850F12AF94d21D470e21bE9D0E9C Ethereum node RPC URL https://limbo.liquidity.network/ethrpc

  13. NOCUST - setup const Web3 = require('web3') // Web3 1.0.0-beta.37 only for now const BigNumber = require('bignumber.js') const { NOCUSTManager } = require('nocust-client') // Setup web3 with Infura const web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/')); // Add bob’s private key to web3 instance for signing transactions const bobPrivateKey = '0xf6a0b0f4fa95051d0d58582d2a4182f02c602d1e54c6a9e4dbed07faa51e0385' const bob = web3.eth.accounts.privateKeyToAccount(bobPrivateKey).address web3.eth.accounts.wallet.add(bobPrivateKey) // Main nocust manager object const nocustManager = new NOCUSTManager({ rpcApi: web3, operatorApiUrl: 'https://rinkeby.liquidity.network/', contractAddress: '0x66b26B6CeA8557D6d209B33A30D69C11B0993a3a', });

  14. NOCUST - Registration // Register Bob's public key await nocustManager.registerAddress(bob) ● Adds Bob’s leaf into the Merkle tree/off-chain ledger Fully off-chain operation (No blockchain transaction will be sent) ● ● Registration signs a message with Bob’s private key

  15. NOCUST - Deposit // Deposit ETH -> fETH await nocustManager.deposit( bob, // Depositor "100000000000000000", // Amount to deposit (in wei) "6000000000", // Gas price (in wei) 200000 // Gas limit ) ● It will make a blockchain transaction (on-chain!) Deposit needs 20 blocks confirmation to be credited off-chain ●

  16. NOCUST - Get Bob’s ofg-chain balance // Off-chain Ether balance const bobBalance = await nocustManager.getNOCUSTBalance(bob)

  17. NOCUST - Send an ofg-chain transaction const txId = await nocustManager.sendTransaction({ to: alice, amount: '10', // in wei from: bob, }); ● ⚠ The recipient needs to have registered in the past ! Automatically signs the required messages under the hood ● ● No transaction fees, instant 🔦 🚁

  18. NOCUST - Withdrawals (Request) // First check how much is avaialbe to withdraw (!= balance) const withdrawalLimit = nocustManager.getWithdrawalLimit(bob) // Send the withdrawal request const transactionHash = await nocustManager.withdrawalRequest( bob, // Account from which to make the withdrawal withdrawalLimit, // Amount to withdraw '10000000000', // Gas price, 10 Gwei 300000 // Gas Limit ); ● A withdrawal is a 2 step process (Request + confirmation) ● It takes some time, between 36h and 72h ● Freshly received off-chain funds are not immediately available

  19. NOCUST - Withdrawals (Confimration) if((await nocustManager.getBlocksToWithdrawalConfirmation(bob)) === 0) { const transactionHash = await nocustManager.withdrawalConfirmation( bob, // Account from which to make the withdrawal '1000000000', // Gas price, 10 Gwei 300000 // Gas Limit ); } ● To call after clearing period (Between 36h and 72h) Effectively transfer the funds on-chain to Bob’s address ●

  20. NOCUST - ERC-20 support const daiTokenAddress = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359' // Register Bob's public key for off-chain DAI await nocustManager.registerAddress(bob, daiTokenAddress) // DAI off-chain transfer const txId = await nocustManager.sendTransaction({ to: alice, amount: '10', // in wei from: faucet, token: daiTokenAddress, }); // Off-chain DAI balance const bobBalance = await nocustManager.getNOCUSTBalance(bob, daiTokenAddress) ● ⚠ Token needs to have been whitelist by the operator for use.

  21. NOCUST - Exercise, in-browser wallet 1. Generate key pairs for Alice and Bob 2. Register the addresses with the commit-chain 3. Send funds from Bob to Alice

  22. NOCUST - Exercise, in-browser wallet Clone the repo and follow the instructions at: https://github.com/liquidity-network/nocust-exercise

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend