$ ssh pi@192.168.1.105
sudo pip install virtualenv virtualenvwrapper
export WORKON_HOME=~/Envs
mkdir -p $WORKON_HOME
source /usr/local/bin/virtualenvwrapper.sh
mkvirtualenv -p /usr/bin/python3.5 uRaiden
git clone https://github.com/raiden-network/microraiden.git
cd microraiden/
sudo apt-get install libffi-dev libtool python-dev libssl-dev python-setuptools build-essential automake pkg-config libgmp-dev
pip install -r requirements.txt
python setup.py develop
As the next step, you are going to setup the raspberry pi (Sender) as the µRaiden client or the and our PC as as the µRaiden proxy server (Receiver) as well as the web3 provider running a geth node synced to Ropsten testnet. Next, you will run the echo_server
and the echo_client
examples from the microraiden/examples
folder. The echo_client
on the raspberry pi, and the echo_server
on your PC.
Please make sure that the raspberry pi and your PC are in the same network.
Start geth with these flags(run this command on PC)
geth --testnet --syncmode "fast" --rpc --rpcapi eth,net,web3,personal --rpcaddr 0.0.0.0 --rpcport 8545 --rpccorsdomain "*" --cache 256
The rpcaddr as 0.0.0.0 means that a given socket is listening on all the available IP addresses the computer has. This is important so that µRaiden client on the raspberry can use it as a web3 provider.
Before running both the client or the server make sure that both the sender and receiver addresses have .:doc:TKN balances for opening channels <blockchain>.
In the ~/microraiden/microraiden/examples
folder go to the echo_server.py
and go to the part where we start the server.(These set of actions are performed on your PC)
cd ~/microraiden/microraiden/examples
# Start the app. proxy is a WSGI greenlet, so you must join it properly.
app.run(debug=True)
Change the app.run to include arguments for the host and port
app.run(host="192.168.1.104", port=5000, debug=True)
192.168.1.104
This IP could be different your set-up. Include the IP address of the interface on your PC that is connected to the raspberry pi.
$ python -m echo_server --private-key ~/.ethereum/testnet/keystore/UTC--2016-07-27T07-40-38.092883212Z--9d80d905bc1e106d5bd0637c12b893c5ab60cb41
Enter the private key password:
INFO:filelock:Lock 139916998263696 acquired on ~/.config/microraiden/echo_server.db.lock
INFO:blockchain:starting blockchain polling (interval 2s)
Navigate to the cloned microraiden repository and modify the following files on the raspberry pi.
cd ~/microraiden/microraiden
microraiden/constants.py
file change the WEB3_PROVIDER_DEFAULT value to "http://192.168.1.104:8545"
where 192.168.1.104
is the IP address of the PC where we started the geth node and the µRaiden echo_server
.sudo nano microraiden/constants.py
microraiden/examples/echo_client.py
change endpoint_url
parameter of the run function
definition which looks like thisdef run(
private_key: str,
password_path: str,
resource: str,
channel_manager_address: str = None,
web3: Web3 = None,
retry_interval: float = 5,
endpoint_url: str = 'http://localhost:5000'
):
to the interface of the PC like this endpoint_url: str = 'http://192.168.1.104:5000'
. This enables the raspberry to make a request to the server.
sudo nano microraiden/examples/echo_client.py
Now we run the echo_client.py like this
(uRaiden) pi@raspberrypi:~/microraiden/microraiden $ python -m microraiden.examples.echo_client --private-key ~/.ethereum/testnet/keystore/UTC--2018-02-12T08-35-34.437506909Z--9a7d8c3116258c1f50f3c8ac67d120af58a46ceb --resource /echofix/hello
Enter the private key password:
INFO:microraiden.client.client:Creating channel to 0x9d80D905bc1E106d5bd0637c12B893c5Ab60CB41 with an initial deposit of 50 @2684938
WARNING:microraiden.client.session:Newly created channel does not have enough confirmations yet. Retrying in 5 seconds.
INFO:root:Got the resource /echofix/hello type=text/html; charset=utf-8:
hello
You should get an output like above.The server should also give an output like this showing the requested resource
INFO:channel_manager:unconfirmed channel event received (sender 0x9A7d8c3116258C1F50f3c8ac67d120af58a46CeB, block_number 2684940)
192.168.1.109 - - [2018-02-20 00:41:05] "GET //echofix/hello HTTP/1.1" 402 391 0.010679
INFO:channel_manager:new channel opened (sender 0x9A7d8c3116258C1F50f3c8ac67d120af58a46CeB, block number 2684940)
INFO:__main__:Resource requested: http://192.168.1.104:5000/echofix/hello with param "hello"
192.168.1.109 - - [2018-02-20 00:41:10] "GET //echofix/hello HTTP/1.1" 200 120 0.060261
Through this example we hope developers can develop their own machine to machine clients and their respective server to use microraiden for micropayments according to their respective use cases, using these resources.
Failed building wheel for secp256k1.
If you encounter this problem its mostly your openssl not being compatible with the libsecp256k1 library. secp256k1 is the python binding for this library.
To check whether libsecp256k1 is installed do the following:
(uRaiden) pi@raspberrypi:~ $ apt list --installed *secp256k1*
Listing... Done
(uRaiden) pi@raspberrypi:~ $ apt list *secp256k1*
Listing... Done
libsecp256k1-0/stable 0.1~20161228-1 armhf
libsecp256k1-dev/stable 0.1~20161228-1 armhf
The installed
option tells us whether the package is installed. Since we have none it does not print anything. Later we list the packages which exists in raspbian repository of packages. We install both the packages.
sudo apt-get install libsecp256k1-0 libsecp256k1-dev
After this we go to the releases page of secp256k1 and download the tar.gz of 0.13.2.4 (version as of writing of this tutorial) like this.
wget https://github.com/ludbb/secp256k1-py/archive/0.13.2.4.tar.gz
From the current folder we install tar.gz package of secp256k1 like this.
pip install 0.13.2.4.tar.gz
After this again install requirements.txt
pip install -r requirements.txt
For Transferring file from your machine to the Raspberry pi refer to this documentation
https://www.raspberrypi.org/documentation/remote-access/ssh/sftp.md
You could download and use filezilla.
Footnotes
[1] | All robot icons made by Freepic from http://www.flaticon.com. |
[2] | Raspberry PI Pictograms by TinkTank.club |
[3] | All other icons from http://icomoon.io IcoMoon Icon Pack Free, licensed under a Creative Commons Attribution 4.0 International License |