Skip to content

Local ILP testnet using Quartz Token

Ámbar Tenorio-Fornés edited this page May 24, 2022 · 12 revisions

Note: This process is still being worked on, and it currently doesn't work properly

We will be adapting the ILP tutorial to spin up a local network, while deploying the Quartz token, for it to be used in the transactions.

Download docker images

docker pull interledgerrs/ilp-node
docker pull interledgerrs/ilp-cli
docker pull interledgerrs/ilp-settlement-ethereum
docker pull trufflesuite/ganache-cli
docker pull interledgerjs/settlement-xrp
docker pull redis

Set up the environment

Start as explained in the ILP tutorial. The network, the redis container and the local Ethereum testnet must be initialized:

docker network create --subnet=192.168.128.0/24 local-ilp

docker run -d \
  --name redis \
  --network local-ilp \
  --ip 192.168.128.111 \
  redis

docker run -d \
  --name ethereum-testnet \
  --network local-ilp \
  --ip 192.168.128.2 \
  trufflesuite/ganache-cli \
  -m "abstract vacuum mammal awkward pudding scene penalty purchase dinner depart evoke puzzle" \
  -i 1

Create the token

Note: If you have downloaded the code from the repository, you can ignore this section. Skip to Deploy the token.

The token must be deployed in the local ethereum testnet (inside the container ethereum-testnet).

In the command line, do the following:

mkdir mytoken && cd mytoken
npm init -y

npm i --save-dev @openzeppelin/contracts

npm i truffle -g

npx truffle init

The truffle-config.jsfile must be modified adding a new network inside networks. This new network will be called docker and will be as follows:

module.exports = {
  networks: {
    docker: {
      host: "192.168.128.2",
      port: 8545,
      network_id: "*" // Match any network id
    }
  }
};

Where host is the ip of the Ethereum network that we are using (in this case, the testnet ethereum-testnet).

Create a new contract inheriting from ERC20 and implementing the new token.

Once that is done, write a script for the deployment of the contract and add it to the /migrations folder (in this instance, this will be for deploying the Quartz token). In this deployment script, the necessary parameters to initialize the contract must be provided (in this case, the amount of tokens that will be minted when the contract is deployed).

In truffle-config.js, change the compiler version to 0.6.12. Keep an eye in the Solidity versions. The source files currently work for Solidity versions >=0.6.0 <0.8.0, but this could possibly change.

Deploy the token

Note: If you haven't followed the previous section, start with an npm install.

First, compile the contracts:

truffle compile

Then, migrate the contracts to the docker network:

truffle migrate --network docker

Copy the contract address that has been generated. This will be later used when initializing the dockers for the ethereum nodes.

Open the Truffle console in the docker network:

truffle console --network docker

Now that the contract has been deployed, it can be accessed and interacted with by assigning the contract instance to a variable.

let quartz = await ERC20Quartz.deployed()

This operation can only be performed by the issuer of the contract. For anybody else with access to the network to have an instance of the contract to interact with, they must be provided the address of the contract, so they can do:

let quartz = await ERC20Quartz.at(<contract address in quotes>)

The contract address can be consulted by doing:

quartz.address

To check the accounts existing within the blockchain (to make a transaction to one of them or consult their balance) they can be consulted from the Truffle console:

accounts

If the initialization of the contract worked correctly, the first of the accounts, wich corresponds to the issuer (and will be later assigned to Alice) should have all the tokens that have been minted in the initialization.

let balance = await quartz.balanceOf(<public key of the first account>)
balance.toNumber()

toNumber is necessary so the information is displayed in a natural way.

Start the ILP nodes

Following the ILP tutorial, initialize the nodes. A couple considerations have to be made:

  • The token_address is the address of the ERC20Quartz contract.
  • The ip's of the nodes are fixed, based on the ip of the local ethereum testnet (this initial ip can be checked from the console of the docker where the network is running). In this case, the ip of the network was set manually.
  • The asset scale is fixed to 9.
  • The exchange rate is provided by the API, so the parameter exchange_rate.provider is deleted.
docker run -d \
  --name alice-eth \
  --network local-ilp \
  -e "RUST_LOG=interledger=trace" \
  --ip 192.168.128.3 \
  interledgerrs/ilp-settlement-ethereum \
  --private_key 380eb0f3d505f087e438eca80bc4df9a7faa24f868e69fc0440261a0fc0567dc \
  --confirmations 0 \
  --poll_frequency 1000 \
  --ethereum_url http://ethereum-testnet:8545 \
  --token_address 0x770bC1820890415bB14a3B8f992c19caA74906aD \
  --connector_url http://alice-node:7771 \
  --redis_url redis://redis:6379/0 \
  --asset_scale 9 \
  --settlement_api_bind_address 0.0.0.0:3000

docker run -d \
  --name alice-node \
  --network local-ilp \
  -e "RUST_LOG=interledger=trace" \
  --ip 192.168.128.4 \
  interledgerrs/ilp-node \
  --ilp_address example.alice \
  --secret_seed 8852500887504328225458511465394229327394647958135038836332350604 \
  --admin_auth_token hi_alice \
  --redis_url redis://redis:6379/1 \
  --http_bind_address 0.0.0.0:7770 \
  --settlement_api_bind_address 0.0.0.0:7771


docker run -d \
  --name bob-eth \
  --network local-ilp \
  -e "RUST_LOG=interledger=trace" \
  --ip 192.168.128.5 \
  interledgerrs/ilp-settlement-ethereum \
  --private_key cc96601bc52293b53c4736a12af9130abf347669b3813f9ec4cafdf6991b087e \
  --confirmations 0 \
  --poll_frequency 1000 \
  --ethereum_url http://ethereum-testnet:8545 \
  --token_address 0x770bC1820890415bB14a3B8f992c19caA74906aD \
  --connector_url http://bob-node:7771 \
  --redis_url redis://redis:6379/2 \
  --asset_scale 9 \
  --settlement_api_bind_address 0.0.0.0:3000

docker run -d \
  --name bob-xrp \
  --network local-ilp \
  -e "DEBUG=settlement*" \
  -e "CONNECTOR_URL=http://bob-node:7771" \
  -e "REDIS_URI=redis://redis:6379/3" \
  -e "ENGINE_PORT=3001" \
  --ip 192.168.128.6 \
  interledgerjs/settlement-xrp

docker run -d \
  --name bob-node \
  --network local-ilp \
  -e "RUST_LOG=interledger=trace" \
  --ip 192.168.128.7 \
  interledgerrs/ilp-node \
  --ilp_address example.bob \
  --secret_seed 1604966725982139900555208458637022875563691455429373719368053354 \
  --admin_auth_token hi_bob \
  --redis_url redis://redis:6379/4 \
  --http_bind_address 0.0.0.0:7770 \
  --settlement_api_bind_address 0.0.0.0:7771


docker run -d \
  --name charlie-xrp \
  --network local-ilp \
  -e "DEBUG=settlement*" \
  -e "CONNECTOR_URL=http://charlie-node:7771" \
  -e "REDIS_URI=redis://redis:6379/5" \
  -e "ENGINE_PORT=3000" \
  --ip 192.168.128.8 \
  interledgerjs/settlement-xrp

docker run -d \
  --name charlie-node \
  --network local-ilp \
  -e "RUST_LOG=interledger=trace" \
  --ip 192.168.128.9 \
  interledgerrs/ilp-node \
  --secret_seed 1232362131122139900555208458637022875563691455429373719368053354 \
  --admin_auth_token hi_charlie \
  --redis_url redis://redis:6379/6 \
  --http_bind_address 0.0.0.0:7770 \
  --settlement_api_bind_address 0.0.0.0:7771

Next, change the exchange rates for the new coin using the API:

curl -X PUT "http://192.168.128.4:7770/rates" -H "Authorization: Bearer hi_alice" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"QTZ\":1.00,\"XRP\":0.000283}"
curl -X PUT "http://192.168.128.7:7770/rates" -H "Authorization: Bearer hi_bob" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"QTZ\":1.00,\"XRP\":0.000283}"
curl -X PUT "http://192.168.128.9:7770/rates" -H "Authorization: Bearer hi_charlie" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{\"QTZ\":1.00,\"XRP\":0.000283}"

After that, create the accounts. Also here, a couple considerations have to be taken:

  • In the Alice and Bob accounts that used ETH in the example, the asset code is now QTZ.
  • The asset-scale is now 0.
alias   alice-cli="docker run --rm --network local-ilp interledgerrs/ilp-cli --node http://alice-node:7770"
alias     bob-cli="docker run --rm --network local-ilp interledgerrs/ilp-cli --node http://bob-node:7770"
alias charlie-cli="docker run --rm --network local-ilp interledgerrs/ilp-cli --node http://charlie-node:7770"

alice-cli accounts create alice \
  --auth hi_alice \
  --ilp-address example.alice \
  --asset-code QTZ \
  --asset-scale 9 \
  --ilp-over-http-incoming-token alice_password

alice-cli accounts create bob \
  --auth hi_alice \
  --ilp-address example.bob \
  --asset-code QTZ \
  --asset-scale 9\
  --settlement-engine-url http://alice-eth:3000 \
  --ilp-over-http-incoming-token bob_password \
  --ilp-over-http-outgoing-token alice_password \
  --ilp-over-http-url http://bob-node:7770/accounts/alice/ilp \
  --settle-threshold 100000 \
  --settle-to 0 \
  --routing-relation Peer

bob-cli accounts create alice \
  --auth hi_bob \
  --ilp-address example.alice \
  --asset-code QTZ \
  --asset-scale 9 \
  --max-packet-amount 100000 \
  --settlement-engine-url http://bob-eth:3000 \
  --ilp-over-http-incoming-token alice_password \
  --ilp-over-http-outgoing-token bob_password \
  --ilp-over-http-url http://alice-node:7770/accounts/bob/ilp \
  --min-balance -150000 \
  --routing-relation Peer

bob-cli accounts create charlie \
  --auth hi_bob \
  --asset-code XRP \
  --asset-scale 6 \
  --settlement-engine-url http://bob-xrp:3001 \
  --ilp-over-http-incoming-token charlie_password \
  --ilp-over-http-outgoing-token bob_other_password \
  --ilp-over-http-url http://charlie-node:7770/accounts/bob/ilp \
  --settle-threshold 10000 \
  --settle-to -1000000 \
  --routing-relation Child

charlie-cli accounts create bob \
  --auth hi_charlie \
  --ilp-address example.bob \
  --asset-code XRP \
  --asset-scale 6 \
  --settlement-engine-url http://charlie-xrp:3000 \
  --ilp-over-http-incoming-token bob_other_password \
  --ilp-over-http-outgoing-token charlie_password \
  --ilp-over-http-url http://bob-node:7770/accounts/charlie/ilp \
  --min-balance -50000 \
  --routing-relation Parent

charlie-cli accounts create charlie \
  --auth hi_charlie \
  --asset-code XRP \
  --asset-scale 6 \
  --ilp-over-http-incoming-token charlie_password

Perform the payment

Send a certain amount of tokens from Alice to Charlie:

alice-cli pay alice \
  --auth alice_password \
  --amount 20 \
  --to http://charlie-node:7770/accounts/charlie/spsp

Delete the nodes and start over

Only deleting the nodes, but keeping the network

Delete the accounts:

alice-cli accounts delete alice --auth hi_alice
alice-cli accounts delete bob --auth hi_alice
bob-cli accounts delete alice --auth hi_bob
bob-cli accounts delete charlie --auth hi_bob
charlie-cli accounts delete bob --auth hi_charlie
charlie-cli accounts delete charlie --auth hi_charlie

Remove the dockers:

docker stop alice-node bob-node charlie-node alice-eth bob-eth bob-xrp charlie-xrp
docker rm alice-node bob-node charlie-node alice-eth bob-eth bob-xrp charlie-xrp

Remove everything

docker stop redis ethereum-testnet alice-node bob-node charlie-node alice-eth bob-eth bob-xrp charlie-xrp
docker rm redis ethereum-testnet alice-node bob-node charlie-node alice-eth bob-eth bob-xrp charlie-xrp
docker network rm local-ilp