{"id":21280839,"url":"https://github.com/consensysmesh/local-raiden","last_synced_at":"2025-07-11T10:33:00.348Z","repository":{"id":87483249,"uuid":"115130669","full_name":"ConsenSysMesh/Local-Raiden","owner":"ConsenSysMesh","description":"Run a local Raiden network in docker containers for demo and testing purposes.","archived":false,"fork":false,"pushed_at":"2018-06-12T13:36:30.000Z","size":92,"stargazers_count":15,"open_issues_count":2,"forks_count":7,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-08-07T06:02:00.393Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ConsenSysMesh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-12-22T16:08:05.000Z","updated_at":"2024-08-07T06:02:00.394Z","dependencies_parsed_at":"2023-07-16T07:02:13.699Z","dependency_job_id":null,"html_url":"https://github.com/ConsenSysMesh/Local-Raiden","commit_stats":null,"previous_names":["consensys/local-raiden"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConsenSysMesh%2FLocal-Raiden","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConsenSysMesh%2FLocal-Raiden/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConsenSysMesh%2FLocal-Raiden/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConsenSysMesh%2FLocal-Raiden/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ConsenSysMesh","download_url":"https://codeload.github.com/ConsenSysMesh/Local-Raiden/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225715945,"owners_count":17512908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-21T10:41:32.635Z","updated_at":"2024-11-21T10:41:33.285Z","avatar_url":"https://github.com/ConsenSysMesh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A local Raiden test network\n\n* [Introduction](#introduction)\n* [Setting-up](#setting-up)\n* [Raiden contract deployment](#raiden-contract-deployment)\n* [Running Raiden](#running-raiden)\n* [Exploring Raiden](#exploring-raiden)\n* [Notes](#notes)\n\n## Introduction\n\nThe goal is to set up a local Raiden network running in Docker containers, allowing for easier exploration and experimentation than using the Ropsten testnet version.\n\nAdvantages:\n\n* No need to keep a synced Ropsten node up and running.\n* No need to get hold of Ropsten test Ether.\n* Faster, more predictable blocktimes.\n* No tricky NAT issues to deal with.\n* Easy tear-down and restart - it's not permanent :-)\n\nThe set-up is a single Docker container representing the Ethereum blockchain, in the form of a `geth --dev` node, and _N_ containers for Raiden clients that communicate with each other and the blockchain.\n\nRaiden is at the \"Developer Preview\" stage, and comes with a [disclaimer and notes](http://raiden-network.readthedocs.io/en/stable/what_is_the_dev_preview.html#disclaimer). The official Dev Preview version is 0.2.0, but that has a [bug](https://github.com/raiden-network/raiden/pull/1141) around closing channels. For this reason we are using a more recent commit. Unfortunately, that breaks the nice Web GUI... we'll have to live without it for now.\n\nBackground reading on Raiden:\n\n* [Raiden Network: Vision, Challenges and Roadmap](https://medium.com/@raiden_network/raiden-network-vision-challenges-and-roadmap-593dfa34b868)\n  * A gentle introduction to the key points\n* [Raiden FAQ](https://raiden.network/faq.html)\n  * Lots of ELI5 stuff.\n* [What is the Raiden Network?](https://raiden.network/101.html)\n  * A 101 on the technology. The next level down.\n* [The official documentation](http://raiden-network.readthedocs.io/en/stable/spec.html)\n* [The Raiden GitHub](https://github.com/raiden-network/raiden)\n\n## Setting up\n\n### Prerequisites\n\nThere are some prerequisites:\n\n1. Docker (with docker-compose), and\n2. Node.js, with [web3](https://www.npmjs.com/package/web3) installed. web3 must be version 1.0.\n3. The [Solidity compiler](http://solidity.readthedocs.io/en/develop/installing-solidity.html#binary-packages)\n\nMy environment:\n\n```\n\u003e uname -a\nLinux Lubuntu-Nov17 4.13.0-21-generic #24-Ubuntu SMP Mon Dec 18 17:29:16 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux\n\u003e docker --version\nDocker version 17.12.0-ce, build c97c6d6\n\u003e node --version\nv8.9.3\n\u003e npm --version\n5.6.0\n\u003e npm list web3\n/home/ben/Everything/Ethereum/Raiden/Local-Raiden\n└── web3@1.0.0-beta.26\n\u003e /usr/local/bin/solc --version\nsolc, the solidity compiler commandline interface\nVersion: 0.4.19-develop.2018.1.3+commit.c4cbbb05.Linux.g++\n```\n\n### Cloning\n\nSince we include the Raiden repository as a submodule, you will likely need to do the following after cloning (or do a recursive clone).\n\n```\ngit submodule update --init\n```\n\n### Docker images\n\nWe use the [official Docker image](https://hub.docker.com/r/ethereum/client-go/) for Geth, which you can get with,\n\n```\ndocker pull ethereum/client-go\n```\n\nWe need to build an image for the Raiden client. Do the following in the _Local-Raiden_ directory. This will take a while, but needs doing only once.\n\n```\ndocker build -t my/raiden .\n```\n\n## Raiden contract deployment\n\nRaiden essentially consists of two components.\n\n1. The Raiden client that we built above. This communicates with other Raiden clients to make payments, and occasionally with the blockchain to open, close and settle payment channels.\n\n2. A set of [smart contracts](https://github.com/raiden-network/raiden/tree/v0.2.0/raiden/smart_contracts/) that need to be deployed.\n\nSo, we need to deploy the contracts to our test network. Raiden provides a [Python script](https://github.com/raiden-network/raiden/blob/v0.2.0/tools/deploy.py) for this, but my Python-fu is weak and I ended up with all sorts of dependency issues. So I reverted to something more familiar and made the [_deploy.js_](deploy.js) Node.js script instead.\n\nWorking in the _Local-Raiden_ directory, first clear out any old Geth or Raiden data. **Do not do this on your Mainnet configuration! This deletes the keystore.**\n\n```\nrm -rf keystore geth raiden_data geth.ipc\n```\n\nNow check the configuration options near the top of the [_deploy.js_](deploy.js) file and adjust anything that needs adjusting. For example, you may need to edit the path to the Solidity compiler, `SOLC`.\n\nStart a Geth Docker container. All the config is already set up in the _docker-compose.yml_ file, so we can just do the following.\n\n```\ndocker-compose run -u $UID geth\n```\n\nFinally, run the deployment script.\n\n```\nDEBUG=1 node deploy.js\n```\n\nThis will output progress, and a summary of the final status. It will also create a _.env_ file containing environment variables to be passed to docker-compose.\n\nFinally, stop Geth (`Ctrl-C` will do it). All being well, everything is now set up on the blockchain within the _geth_ directory. Don't delete this directory if you want to keep the blockchain state.\n\n### Discussion\n\nThe output should resemble the following, different addresses for accounts and contracts.\n\n```\nSummary\n=======\n\nDeployment account: 0x78910ad1D145B20fdcd31B20D43D82dd998C194A\nAccount_0: 0x19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A\n  balance: 2000000000000000000000\n  tokens:  250000\nAccount_1: 0x1563915e194D8CfBA1943570603F7606A3115508\n  balance: 2000000000000000000000\n  tokens:  250000\nAccount_2: 0x5CbDd86a2FA8Dc4bDdd8a8f69dBa48572EeC07FB\n  balance: 2000000000000000000000\n  tokens:  250000\nAccount_3: 0x7564105E977516C53bE337314c7E53838967bDaC\n  balance: 2000000000000000000000\n  tokens:  250000\nDiscovery contract: 0x019Ae5c6C16C1356ccDe9cc2DB5415a259a0F2C5\nRegistry contract:  0xd1AFb72FFA57e4163175EFB9179bB63b500BB3b0\nToken contract:     0x2e8EdB207922794aEcB1A2cDC5a730612eefF034\n```\n\nThe deployment script performs the following tasks.\n\n1. Transfers (test) Ether from Geth's pre-funded account to the four accounts that we have set up in _keystore/_.\n\n2. Deploys contracts as follows,\n\n   a. the Discovery contract, _EndpointRegistry.sol_\n\n   b. the Netting Channel Library contract, _NettingChannelLibrary.sol_\n\n   c. the Channel Manager Library contract, _ChannelManagerLibrary.sol_\n\n   d. the Registry contract, _Registry.sol_\n\n   e. an ERC20 Token contract, _Token.sol_\n\n3. For all of the above, and in addition _ChannelManagerContract.sol_ and _NettingChannelContract.sol_, the ABI is saved in the _abis_ folder for later use.\n\n4. The tokens in the ERC20 token contract are split equally between the four accounts.\n\n5. Values required by docker-compose are written to the _.env_ file. This _.env_ file is also a useful reference for looking up account and contract addresses later.\n\n## Running Raiden\n\nNow all we need to do to start the whole network is,\n\n```\ndocker-compose up -d\n```\n\nTo shut it all down,\n\n```\ndocker compose down\n```\n\nGeth and Raiden will store their intermediate states in the _geth_ and _raiden\\_data_ directories respectively, so you can do this repeatedly.\n\nThis sets up two Raiden containers along with a Geth container, configured as follows.\n\n* Geth\n   * RPC interface: `172.13.0.2:8545`\n      * Mapped to `localhost:8545` (optional: for convenience)\n* Raiden 0\n   * RPC interface: `172.13.0.3:5001`\n      * Mapped to `localhost:5001` (optional: for convenience)\n   * Raiden Network interface: `172.13.0.3:40001`\n* Raiden 1\n   * RPC interface: `172.13.0.4:5001`\n      * Mapped to `localhost:5002` (optional: for convenience)\n   * Raiden Network interface: `172.13.0.4:40001`\n\nYou can see the console output of each container with `docker logs`. The container names are output by docker-compose, or by executing `docker ps`.\n\n\n## Exploring Raiden\n\n\u003e The below is a just \"getting started\". I hoping to work on some articles digging deeper into what's going on \"under-the-hood\", including mediated transfers that involve multiple nodes. Watch this space...\n\nNow that our Raiden nodes are running, it is possible to interact with them\nvia their RPC interfaces directly from the shell command line:\n\n```\n\u003e curl http://172.13.0.3:5001/api/1/address\n{\"our_address\": \"0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a\"}\n\u003e curl http://172.13.0.4:5001/api/1/address\n{\"our_address\": \"0x1563915e194d8cfba1943570603f7606a3115508\"}\n```\n\nBut this quickly becomes tedious, especially for the more complex operations. I've created some [JavaScript classes](modules/README.md) in the _modules/_ directory to make this easier. See its [README](modules/README.md) for more info. We use the Node REPL:\n\n```\n\u003e node\n```\n\nFirst set some useful variables to keep from having to copy/paste long strings: the Ethereum addresses of our two nodes and the token contract. Insert the addresses from the deployment in the below: they will differ from the ones here.\n\n\n```\n\u003e var acct0 = '0x19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A'\n\u003e var acct1 = '0x1563915e194D8CfBA1943570603F7606A3115508'\n\u003e var token_address = '0x02cAf13e4b645b3dBf27f6Ae1647356A2410210F'\n```\n\nNow we import the Raiden interface and make an instance for each node.\n\n```\n\u003e var Rdn = require('./modules/raiden.js')\n\u003e var r0 = new Rdn('http://172.13.0.3:5001')\n\u003e var r1 = new Rdn('http://172.13.0.4:5001')\n```\n\nWe can call methods on these Raiden node objects. Everything is asynchronous (this is JavaScript), and all methods return Promises, hence the clunky `.then(console.log)` part. I've also edited the output to clean up all the Promise junk that gets printed. [If anyone knows how to (nicely) make synchronous calls to async functions from the REPL (`await` is not available), please get in touch!]\n\n```\n\u003e r0.address().then(console.log)\n{ our_address: '0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a' }\n\u003e r1.address().then(console.log)\n{ our_address: '0x1563915e194d8cfba1943570603f7606a3115508' }\n```\n\nNow, let's register the token. The Registry contract will create a Channel Manager contract that will oversee all channels that exchange this token. This interacts with the blockchain, so takes a few seconds to resolve.\n\n```\n\u003e r0.tokens.register(token_address).then(console.log)\n{ channel_manager_address: '0x7f799b2c9fc03f10e8cabdb06bf916402bab1a8f' }\n```\n\nWith that done we can create a channel between Node0 and Node1 to allow tokens to be exchanged off-chain. This creates another smart contract called a Netting Channel that is responsible only for transfers of this token between these two nodes. It also makes a token transfer into the Netting Contract from Node0's balance (the deposit, 100 tokens in this case). Once again, it takes a few seconds.\n\n```\n\u003e r0.channels.open(acct1, token_address, 100, 30).then(console.log)\n{ partner_address: '0x1563915e194d8cfba1943570603f7606a3115508',\n  balance: 100,\n  reveal_timeout: 10,\n  settle_timeout: 30,\n  state: 'opened',\n  channel_address: '0x6432ed34e54ccc4e3219e5ec65f398d02cff2b89',\n  token_address: '0x02caf13e4b645b3dbf27f6ae1647356a2410210f' }\n```\n\nThe `settle_timeout` is the last parameter and is the number of blocks that the settlement window remains open for challenges after a channel is closed.\n\nWe can now make some transfers!\n\nNode0 sends 50 tokens to Node1. We check balances before and after:\n\n```\n\u003e var channel = '0x6432ed34e54ccc4e3219e5ec65f398d02cff2b89'\n\u003e r0.channels.balance(channel).then(console.log)\n100\n\u003e r1.channels.balance(channel).then(console.log)\n0\n\n\u003e r0.transfer(token_address, acct1, 50).then(console.log)\n\u003e { target_address: '0x1563915e194d8cfba1943570603f7606a3115508',\n  amount: 50,\n  identifier: 6889929806137958000,\n  token_address: '0x02caf13e4b645b3dbf27f6ae1647356a2410210f',\n  initiator_address: '0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a' }\n\n\u003e r0.channels.balance(channel).then(console.log)\n50\n\u003e r1.channels.balance(channel).then(console.log)\n50\n```\n\nThis is instantaneous! The blockchain is not involved. We can check the token balance on the actual blockchain using a different module provided in the _modules/_ directory. This uses Web3 to access the Raiden contracts directly.\n\n```\n\u003e var Contracts = require('./modules/raiden-contracts.js')\n\u003e var contracts = new Contracts('http://172.13.0.2:8545')\n\u003e var token = new contracts.interface(token_address, 'abis/Token.json')\n\u003e token.balanceOf(acct0).then(console.log)\n249900\n\u003e token.balanceOf(acct1).then(console.log)\n250000\n```\n\nNode0's actual token balance has decreased from the initial 250000 by the 100 tokens initially lodged as a deposit. Node1's balance is unchanged. The 50 token Raiden transfer has not yet been reflected back to the blockchain, and won't be until the channel is settled.\n\nWe can continue to send tokens back and forth between the nodes, subject to a cap of original deposit + net tokens received in this channel. However, to release the tokens back to the blockchain and make the transfers \"real\", we need to close the channel down. There is (currently) no way to keep the channel open and extract some of the balance.\n\nNode1 will initiate the channel closing process. This involves a call to the Netting Contract, so takes a few seconds.\n\n```\n\u003e r1.channels.close(channel).then(console.log)\n{ partner_address: '0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a',\n  balance: 50,\n  reveal_timeout: 10,\n  settle_timeout: 30,\n  state: 'opened',\n  channel_address: '0x6432ed34e54ccc4e3219e5ec65f398d02cff2b89',\n  token_address: '0x02caf13e4b645b3dbf27f6ae1647356a2410210f' }\n```\n\nEventually, after waiting for `settle_timeout` blocks, the channel state is marked `'settled'` and we can see the token balances of each account have been correctly updated on the blockchain.  It is no longer possible to make transfers on this channel.\n\n```\n\u003e r1.channels.info(channel).then(console.log)\n{ partner_address: '0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a',\n  balance: 50,\n  reveal_timeout: 10,\n  settle_timeout: 30,\n  state: 'settled',\n  channel_address: '0x6432ed34e54ccc4e3219e5ec65f398d02cff2b89',\n  token_address: '0x02caf13e4b645b3dbf27f6ae1647356a2410210f' }\n\n\u003e token.balanceOf(acct0).then(console.log)\n249950\n\u003e token.balanceOf(acct1).then(console.log)\n250050\n```\n\n## Notes\n\n### Block times\n\nThe configuration here uses a fixed block time of 3 seconds. You can decrease that to make things quicker, or increase it to more closely match real network times. This line in _docker-compose.yml_,\n\n```\n      --dev.period 3\n```\n\nAlthough `dev.period` can be set to zero, meaning that Geth will produce blocks only on demand, I don't recommend it. Raiden channel settlement times are measured in blocks: if no blocks are produced, channels will never settle.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconsensysmesh%2Flocal-raiden","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconsensysmesh%2Flocal-raiden","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconsensysmesh%2Flocal-raiden/lists"}