Build a scalable dApp with the Liquidity Javascript SDK
Guillaume Felley - BDLT summer school 2019
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 ?
Guillaume Felley - BDLT summer school 2019
What is it ?
➡ Secure transactions, off-the-blockchain The benefits ?
➡ Better user experience
The drawbacks ?
> npm install nocust-client > npm install web3@1.0.0-beta.37 bignumber.js
Install the library from NPM: Install required dependencies:
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
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,
contractAddress: '0x66b26B6CeA8557D6d209B33A30D69C11B0993a3a', });
// Register Bob's public key await nocustManager.registerAddress(bob)
// Deposit ETH -> fETH await nocustManager.deposit( bob, // Depositor "100000000000000000", // Amount to deposit (in wei) "6000000000", // Gas price (in wei) 200000 // Gas limit )
// Off-chain Ether balance const bobBalance = await nocustManager.getNOCUSTBalance(bob)
const txId = await nocustManager.sendTransaction({ to: alice, amount: '10', // in wei from: bob, });
// 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 );
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 ); }
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)
1. Generate key pairs for Alice and Bob 2. Register the addresses with the commit-chain 3. Send funds from Bob to Alice