UNPKG

raiden-ts

Version:

Raiden Light Client Typescript/Javascript SDK

331 lines (329 loc) 25.9 kB
<!doctype html> <html class="default no-js"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Private chains | raiden-ts - v3.1.1</title> <meta name="description" content="Documentation for raiden-ts - v3.1.1"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="../../assets/css/main.css"> <link rel="stylesheet" href="../../assets/css/pages.css"> <script async src="../../assets/js/search.js" id="search-script"></script> </head> <body> <header> <div class="tsd-page-toolbar"> <div class="container"> <div class="table-wrap"> <div class="table-cell" id="tsd-search" data-index="../../assets/js/search.json" data-base="../.."> <div class="field"> <label for="tsd-search-field" class="tsd-widget search no-caption">Search</label> <input id="tsd-search-field" type="text" /> </div> <ul class="results"> <li class="state loading">Preparing search index...</li> <li class="state failure">The search index is not available</li> </ul> <a href="../../index.html" class="title">raiden-ts - v3.1.1</a> </div> <div class="table-cell" id="tsd-widgets"> <div id="tsd-filter"> <a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a> <div class="tsd-filter-group"> <div class="tsd-select" id="tsd-filter-visibility"> <span class="tsd-select-label">All</span> <ul class="tsd-select-list"> <li data-value="public">Public</li> <li data-value="protected">Public/Protected</li> <li data-value="private" class="selected">All</li> </ul> </div> <input type="checkbox" id="tsd-filter-inherited" checked /> <label class="tsd-widget" for="tsd-filter-inherited">Inherited</label> </div> </div> <a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a> </div> </div> </div> </div> <div class="tsd-page-title"> <div class="container"> <ul class="tsd-breadcrumb"> <li> <a href="../../modules.html">raiden-ts - v3.1.1</a> </li> <li> <a href="prerequisites.html">Get Started</a> </li> <li> <a href="private-chain.html">Private chains</a> </li> </ul> <h1>Private chains</h1> </div> </div> </header> <div class="container container-main"> <div class="row"> <div class="col-8 col-content"> <div class="tsd-panel tsd-typography"> <a href="#using-the-light-client-in-different-network-setups" id="using-the-light-client-in-different-network-setups" style="color: inherit; text-decoration: none;"> <h1>Using the Light Client in different network setups</h1> </a> <a href="#table-of-contents" id="table-of-contents" style="color: inherit; text-decoration: none;"> <h2>Table of Contents</h2> </a> <ul> <li><a href="#preface">Preface</a></li> <li><a href="#setting-up-the-light-client-on-a-private-network">Setting up the Light Client on a private network</a><ul> <li><a href="#identifying-the-correct-smart-contract-version">Identifying the correct smart contract version</a></li> <li><a href="#locate-the-smart-contract-version">Locate the smart contract version</a></li> <li><a href="#checkout-correct-version-of-raiden">Checkout correct version of raiden</a></li> </ul> </li> <li><a href="#setting-up-the-development-environment">Setting up the Development Environment</a><ul> <li><a href="#locating-the-smart-contracts">Locating the Smart Contracts</a></li> <li><a href="#starting-the-sdk">Starting the SDK</a></li> <li><a href="#changing-the-dapp-to-work-on-the-private-setup">Changing the dApp to work on the private setup</a></li> </ul> </li> </ul> <a href="#preface" id="preface" style="color: inherit; text-decoration: none;"> <h2>Preface</h2> </a> <p>This guide targets users that want to use the Light Client SDK or dApp with a custom network setup. This includes private chain deployments of the Raiden Network or unsupported networks (e.g., Kovan).</p> <p>To use a private network you first have to deploy the contracts by hand. Start by following this tutorial on how to deploy and run Raiden Network on a private chain:</p> <ul> <li><a href="https://raiden-network.readthedocs.io/en/latest/custom-setups/private_net_tutorial.html">Raiden on Private Network Tutorial</a></li> </ul> <p>After finishing the guide above you should have a running Raiden node along with a private chain with the Raiden Network smart contracts deployed. But before that please go through <strong>Setting up the Light Client on a private network</strong> just below to figure the correct version of <code>raiden-contracts</code> and subsequently of <code>raiden</code> which will help us deploy the raiden contracts correctly.</p> <a href="#setting-up-the-light-client-on-a-private-network" id="setting-up-the-light-client-on-a-private-network" style="color: inherit; text-decoration: none;"> <h2>Setting up the Light Client on a private network</h2> </a> <a href="#identifying-the-correct-smart-contract-version" id="identifying-the-correct-smart-contract-version" style="color: inherit; text-decoration: none;"> <h3>Identifying the correct smart contract version</h3> </a> <p>Before starting your private network setup, you first need to:</p> <ol> <li>Select which version of the Light Client you want to use</li> <li>Locate the version of the smart contracts used in that specific version of the Light Client</li> </ol> <a href="#locate-the-smart-contract-version" id="locate-the-smart-contract-version" style="color: inherit; text-decoration: none;"> <h3>Locate the smart contract version</h3> </a> <p>You can easily find out the version of the smart contracts used in your version of the Light Client by checking the <code>raiden-contracts</code> submodule in the Light Client GitHub repo.</p> <ol> <li>Navigate to the <a href="https://github.com/raiden-network/light-client">GitHub</a> project page</li> <li>Locate the <code>raiden-ts</code> subdirectory and look for the <code>raiden-contracts</code> submodule <em>(something like<code>raiden-contracts @ 770c8cd</code>)</em></li> <li>Look at the commit message and check if it includes the <code>raiden-contracts</code> version. If not, follow the submodule link to the contracts repository and locate the <code>setup.py</code> file. You&#39;ll find the version of the Raiden Contracts by looking at the version variable <em>(<code>VERSION = &#39;0.37.5&#39;</code>)</em></li> </ol> <p>After finding the <code>contracts</code> version you&#39;ll have to go to the <a href="https://github.com/raiden-network/raiden">Raiden</a> repo and locate a version of the python client compatible with your specific version of the smart contracts.</p> <ol> <li>Navigate to the <a href="https://github.com/raiden-network/raiden/blob/v2.0.0/requirements/requirements.txt#L204">requirements.txt</a> in the <code>requirements</code> folder on the Raiden repo at a specific tag for example <code>v2.0.0</code>. list of all <a href="https://github.com/raiden-network/raiden/tags">raiden tags</a>.</li> <li>You can see the <code>contracts</code> version used by looking at the <code>raiden-contracts</code> dependency.</li> </ol> <p>If the python client uses a newer version of the Raiden Contracts, you can navigate to an older tag till you find the version of <code>raiden-contracts</code> dependency compatible with that of the <code>light-client</code> repository you intend to use.</p> <a href="#checkout-correct-version-of-raiden" id="checkout-correct-version-of-raiden" style="color: inherit; text-decoration: none;"> <h3>Checkout correct version of raiden</h3> </a> <p>You need to check out the correct tag in the Raiden repo that you cloned when deploying Raiden Network on a private chain.</p> <p>For example, if you need to use the <code>v2.0.0</code> tag, you need to first checkout the tag before continuing with the <a href="https://raiden-network.readthedocs.io/en/latest/custom-setups/private_net_tutorial.html#install-raiden-and-dependencies">Install Raiden and dependencies</a> tutorial after cloning the raiden repository.</p> <pre><code class="language-bash"><span style="color: #000000">git checkout v2.0.0</span> </code></pre> <p>If you&#39;ve done everything correctly after following <a href="https://raiden-network.readthedocs.io/en/latest/custom-setups/private_net_tutorial.html">Raiden on Private Network Tutorial</a> you should now have <code>Geth</code> running a private chain, with the Raiden contracts deployed, and a Raiden node running.</p> <a href="#setting-up-the-development-environment" id="setting-up-the-development-environment" style="color: inherit; text-decoration: none;"> <h2>Setting up the Development Environment</h2> </a> <a href="#locating-the-smart-contracts" id="locating-the-smart-contracts" style="color: inherit; text-decoration: none;"> <h3>Locating the Smart contracts</h3> </a> <p>After bootstrapping the network you have to locate the deployment files. The deployment files will point the SDK to the correct smart contracts.</p> <p>Locate <code>env/lib/python3.7/site-packages/raiden_contracts/data_${VERSION}/</code>, in the directory that contains the virtual environment that you created when deploying the Raiden Network on a private chain.</p> <p>You should find the two following files in this directory:</p> <ul> <li><code>deployment_private_net.json</code></li> <li><code>deployment_services_private_net.json</code></li> </ul> <p>Create a <code>deployment</code> directory into your project&#39;s <code>src</code>, copy these files there and proceed with the SDK or dApp initialization.</p> <a href="#starting-the-sdk" id="starting-the-sdk" style="color: inherit; text-decoration: none;"> <h3>Starting the SDK</h3> </a> <p>You can start using the SDK in your setup. If you want to learn more about using the SDK in your project you can reference the <a href="https://github.com/raiden-network/light-client#run-the-repository-code">SDK installation</a> tutorial.</p> <p>To start the SDK on your private network setup, you need to import the private deployment files. You can find them in the <code>&lt;rootDir&gt;/src/deployment</code> directory.</p> <pre><code class="language-typescript"><span style="color: #AF00DB">import</span><span style="color: #000000"> </span><span style="color: #001080">privateDeployment</span><span style="color: #000000"> </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;@/deployment/deployment_private_net.json&#039;</span><span style="color: #000000">;</span> <span style="color: #AF00DB">import</span><span style="color: #000000"> </span><span style="color: #001080">privateServicesDeployment</span><span style="color: #000000"> </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;@/deployment/deployment_services_private_net.json&#039;</span><span style="color: #000000">;</span> <span style="color: #AF00DB">import</span><span style="color: #000000"> { </span><span style="color: #001080">ContractsInfo</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;raiden-ts&#039;</span><span style="color: #000000">;</span> </code></pre> <p>As soon as the imports exist, you need to construct the <code>contractsInfo</code> object and pass it to the Light Client SDK initialization logic.</p> <p>An example of the SDK initialization function follows:</p> <pre><code class="language-typescript"><span style="color: #0000FF">async</span><span style="color: #000000"> </span><span style="color: #0000FF">function</span><span style="color: #000000"> </span><span style="color: #795E26">initialization</span><span style="color: #000000">() {</span> <span style="color: #000000"> </span><span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">contractsInfo</span><span style="color: #000000"> = {</span> <span style="color: #000000"> ...</span><span style="color: #001080">privateDeployment</span><span style="color: #000000">.</span><span style="color: #001080">contracts</span><span style="color: #000000">,</span> <span style="color: #000000"> ...</span><span style="color: #001080">privateServicesDeployment</span><span style="color: #000000">.</span><span style="color: #001080">contracts</span><span style="color: #000000">,</span> <span style="color: #000000"> } </span><span style="color: #AF00DB">as</span><span style="color: #000000"> </span><span style="color: #267F99">unknown</span><span style="color: #000000"> </span><span style="color: #AF00DB">as</span><span style="color: #000000"> </span><span style="color: #267F99">ContractsInfo</span><span style="color: #000000">;</span> <span style="color: #000000"> </span><span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">raiden</span><span style="color: #000000"> = </span><span style="color: #AF00DB">await</span><span style="color: #000000"> </span><span style="color: #001080">Raiden</span><span style="color: #000000">.</span><span style="color: #795E26">create</span><span style="color: #000000">(</span><span style="color: #001080">provider</span><span style="color: #000000">, </span><span style="color: #098658">0</span><span style="color: #000000">, </span><span style="color: #001080">window</span><span style="color: #000000">.</span><span style="color: #001080">localStorage</span><span style="color: #000000">, </span><span style="color: #001080">contractsInfo</span><span style="color: #000000">);</span> <span style="color: #000000">}</span> </code></pre> <p>Calling the <code>initialization()</code> function should enable the SDK to manage channels and send payments in the development environment, using the previously deployed token.</p> <a href="#changing-the-dapp-to-work-on-the-private-setup" id="changing-the-dapp-to-work-on-the-private-setup" style="color: inherit; text-decoration: none;"> <h3>Changing the dApp to work on the private setup</h3> </a> <p>Out of the box the dApp supports the following public test networks <code>Görli</code>, <code>Rinkeby</code> and <code>Ropsten</code>.</p> <p>To run the dApp on any other network setup you need to deploy the smart contracts and change the dApp to use this setup.</p> <p>If you require help running the dApp, you can follow the <a href="https://github.com/raiden-network/light-client#install-and-run-the-dapp">instructions</a>.</p> <p>As soon as you have the dApp running you can locate the <a href="https://github.com/raiden-network/light-client/blob/master/raiden-dapp/src/services/raiden-service.ts#L45"><code>createRaiden</code></a> function and change it accordingly.</p> <p>First, you need to import the deployment information, as with the SDK setup.</p> <pre><code class="language-typescript"><span style="color: #AF00DB">import</span><span style="color: #000000"> </span><span style="color: #001080">privateDeployment</span><span style="color: #000000"> </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;@/deployment/deployment_private_net.json&#039;</span><span style="color: #000000">;</span> <span style="color: #AF00DB">import</span><span style="color: #000000"> </span><span style="color: #001080">privateServicesDeployment</span><span style="color: #000000"> </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;@/deployment/deployment_services_private_net.json&#039;</span><span style="color: #000000">;</span> <span style="color: #AF00DB">import</span><span style="color: #000000"> </span><span style="color: #AF00DB">type</span><span style="color: #000000"> { </span><span style="color: #001080">ContractsInfo</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;raiden-ts&#039;</span><span style="color: #000000">;</span> </code></pre> <p>Then you need to construct the <code>contractsInfo</code> object.</p> <p>The <a href="https://github.com/raiden-network/light-client/blob/master/raiden-dapp/src/services/raiden-service.ts#L45"><code>createRaiden</code></a> function should look like the example below:</p> <pre><code class="language-typescript"><span style="color: #000000"> </span><span style="color: #001080">private</span><span style="color: #000000"> </span><span style="color: #001080">static</span><span style="color: #000000"> </span><span style="color: #001080">async</span><span style="color: #000000"> </span><span style="color: #795E26">createRaiden</span><span style="color: #000000">(</span> <span style="color: #000000"> </span><span style="color: #001080">provider</span><span style="color: #000000">: </span><span style="color: #001080">providers</span><span style="color: #000000">.</span><span style="color: #001080">JsonRpcProvider</span><span style="color: #000000"> | </span><span style="color: #001080">string</span><span style="color: #000000">,</span> <span style="color: #000000"> </span><span style="color: #001080">privateKeyOrProviderAccountIndex</span><span style="color: #000000">: </span><span style="color: #001080">string</span><span style="color: #000000"> | </span><span style="color: #001080">number</span><span style="color: #000000"> = </span><span style="color: #098658">0</span><span style="color: #000000">,</span> <span style="color: #000000"> </span><span style="color: #001080">stateBackup</span><span style="color: #000000">?: </span><span style="color: #001080">string</span><span style="color: #000000">,</span> <span style="color: #000000"> </span><span style="color: #001080">subkey</span><span style="color: #000000">?: </span><span style="color: #0000FF">true</span><span style="color: #000000">,</span> <span style="color: #000000"> ): </span><span style="color: #267F99">Promise</span><span style="color: #000000">&lt;</span><span style="color: #001080">Raiden</span><span style="color: #000000">&gt; {</span> <span style="color: #000000"> const </span><span style="color: #001080">contractsInfo</span><span style="color: #000000"> = {</span> <span style="color: #000000"> ...</span><span style="color: #001080">privateDeployment</span><span style="color: #000000">.</span><span style="color: #001080">contracts</span><span style="color: #000000">,</span> <span style="color: #000000"> ...</span><span style="color: #001080">privateServicesDeployment</span><span style="color: #000000">.</span><span style="color: #001080">contracts</span><span style="color: #000000">,</span> <span style="color: #000000"> } </span><span style="color: #AF00DB">as</span><span style="color: #000000"> </span><span style="color: #267F99">unknown</span><span style="color: #000000"> </span><span style="color: #AF00DB">as</span><span style="color: #000000"> </span><span style="color: #267F99">ContractsInfo</span><span style="color: #000000">;</span> <span style="color: #000000">..</span> <span style="color: #000000">..</span> <span style="color: #000000">..</span> <span style="color: #000000"> try {</span> <span style="color: #000000"> </span><span style="color: #008000">// const contracts = await ConfigProvider.contracts();</span> <span style="color: #000000"> return await Raiden.create(</span> <span style="color: #000000"> </span><span style="color: #001080">provider</span><span style="color: #000000">,</span> <span style="color: #000000"> </span><span style="color: #001080">privateKeyOrProviderAccountIndex</span><span style="color: #000000">,</span> <span style="color: #000000"> </span><span style="color: #001080">storageOpts</span><span style="color: #000000">,</span> <span style="color: #000000"> </span><span style="color: #001080">contractsInfo</span><span style="color: #000000">,</span> <span style="color: #000000"> {</span> <span style="color: #000000"> </span><span style="color: #001080">pfsSafetyMargin:</span><span style="color: #000000"> </span><span style="color: #098658">1.1</span><span style="color: #000000">,</span> <span style="color: #000000"> ...(</span><span style="color: #001080">process</span><span style="color: #000000">.</span><span style="color: #001080">env</span><span style="color: #000000">.</span><span style="color: #0070C1">VUE_APP_PFS</span> <span style="color: #000000"> ..</span> <span style="color: #000000"> ..</span> </code></pre> <p>Comment out <code>const contracts = await ConfigProvider.contracts();</code> and add <code>contractsInfo</code> just below the <code>storageOpts</code> variable.</p> <p>Finally with these changes you need to run</p> <pre><code class="language-bash"><span style="color: #000000">yarn workspace raiden-dapp serve</span> </code></pre> <p>You might face issues with linting for that you will need to go in the <code>raiden-dapp</code> subfolder and run the following:</p> <pre><code class="language-bash"><span style="color: #000000">yarn lint:fix</span> </code></pre> <p>To finalize the setup, you also need to change MetaMask&#39;s RPC provider. Simply go MetaMask, find the network dropdown and select <code>Localhost 8545</code>.</p> <blockquote> <p>Note! This assumes that <code>Geth</code> runs on <code>http://localhost:8545</code>.</p> </blockquote> </div> </div> <div class="col-4 col-menu menu-sticky-wrap menu-highlight"> <nav class="tsd-navigation primary"> <ul> <li class="label pp-nav pp-group"> <span>Get <wbr>Started</span> </li> <li class=" pp-nav pp-page"> <a href="prerequisites.html">Prerequisites</a> </li> <li class=" pp-nav pp-page"> <a href="installing-sdk.html">Installing the SDK</a> </li> <li class=" pp-nav pp-page"> <a href="installing-dapp.html">Installing the d<wbr>App</a> </li> <li class=" pp-nav pp-page"> <a href="connecting.html">Connecting</a> </li> <li class="current pp-nav pp-page"> <a href="private-chain.html">Private chains</a> </li> <li class="label pp-nav pp-group"> <span>Usage</span> </li> <li class=" pp-nav pp-page"> <a href="../Usage/opening-channel.html">Opening a channel</a> </li> <li class=" pp-nav pp-page"> <a href="../Usage/funding-channel.html">Funding a channel</a> </li> <li class=" pp-nav pp-page"> <a href="../Usage/direct-transfer.html">Transferring</a> </li> <li class=" pp-nav pp-page"> <a href="../Usage/closing-channel.html">Closing a channel</a> </li> <li class=" pp-nav pp-page"> <a href="../Usage/settling-channel.html">Settling a channel</a> </li> <li class="label pp-nav pp-group"> <span>Using the <wbr>Raiden d<wbr>App</span> </li> <li class=" pp-nav pp-page"> <a href="../Using the Raiden dApp/using-dapp.html">Overview</a> </li> <li class=" pp-nav pp-page"> <a href="../Using the Raiden dApp/navigate-dapp.html">Navigate the <wbr>Raiden d<wbr>App</a> </li> <li class=" pp-nav pp-page"> <a href="../Using the Raiden dApp/hub-selection-channel-opening.html">Hub <wbr>Selection and <wbr>Channel <wbr>Opening</a> </li> <li class=" pp-nav pp-page"> <a href="../Using the Raiden dApp/transfers.html">Transfers</a> </li> <li class=" pp-nav pp-page"> <a href="../Using the Raiden dApp/channels.html">Channels</a> </li> <li class=" pp-nav pp-page"> <a href="../Using the Raiden dApp/account.html">Accounts</a> </li> <li class="label pp-nav pp-group"> <span>Using the <wbr>Raiden CLI</span> </li> <li class=" pp-nav pp-page"> <a href="../Using the Raiden CLI/README.html">Overview</a> </li> <li class=" pp-nav pp-page"> <a href="../Using the Raiden CLI/raspberrypi.html">Running raiden-<wbr>cli on the raspberry pi</a> </li> <li class="label pp-nav pp-group"> <span>API</span> </li> <li class=" "> <a href="../../modules.html">Exports</a> </li> </ul> </nav> <nav class="tsd-navigation secondary menu-sticky"> <ul class="before-current"> </ul> </nav> </div> </div> </div> <footer class="with-border-bottom"> <div class="container"> <h2>Legend</h2> <div class="tsd-legend-group"> <ul class="tsd-legend"> <li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li> <li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li> <li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li> <li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li> </ul> </div> </div> </footer> <div class="container tsd-generator"> <p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p> </div> <div class="overlay"></div> <script src="../../assets/js/main.js"></script> </body> </html>