Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Run E2E PoC

Jonas Hals edited this page Feb 11, 2020 · 25 revisions

Prerequisites

  • You are running a Substrate node with the Chainlink pallet (and example runtime module).

Run a Chainlink node

  1. Create a new directory and cd into it: mkdir ~/.chainlink-substrate && cd ~/.chainlink-substrate

  2. Set up an .env file:

ROOT=/chainlink
LOG_LEVEL=debug
ETH_CHAIN_ID=3
MIN_OUTGOING_CONFIRMATIONS=2
LINK_CONTRACT_ADDRESS=0x20fe562d797a42dcb3399062ae9546cd06f63280
CHAINLINK_TLS_PORT=0
SECURE_COOKIES=false
ALLOW_ORIGINS=*
ETH_URL=wss://ropsten.infura.io/ws
CHAINLINK_DEV=true
  1. Start container: docker run -p 6688:6688 -v ~/.chainlink-substrate:/chainlink -it --env-file=.env smartcontract/chainlink local n

  2. Follow instructions given to set up an account

Add EI to Chainlink node

  1. Open docker container bash: docker exec -it <container name> /bin/bash

You can find the container name/id with docker ps

  1. Authenticate with credentials created above: chainlink admin login

  2. Add EI with chainlink initiators create test-ei http://host.docker.internal:8080/jobs

  3. Take note of the credentials that is output

(Exit out of the docker container)

Run Postgres node

  1. Run Postgres container: docker run -v ~/.chainlink-substrate/pg:/var/lib/postgresql/data --name postgres --rm -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres

  2. Open the psql client: psql -h localhost -U postgres

  3. Enter "password" as the password

  4. Create database: CREATE DATABASE ei;

(Exit out of the psql client with \q)

Run External Initiator

Create ei.env file:

EI_IC_ACCESSKEY= # Enter the Initiator to Chainlink accesskey
EI_IC_SECRET= # Enter the Initiator to Chainlink access secret
EI_CI_ACCESSKEY= # Enter the Chainlink to Initiator accesskey
EI_CI_SECRET= # Enter the Chainlink to Initiator access secret
EI_DATABASEURL=postgres://postgres:password@host.docker.internal:5432/ei?sslmode=disable
EI_CHAINLINKURL=http://host.docker.internal:6688/

Use the credentials generated during Add EI to Chainlink node

Run using Docker: (If you're not running the Substrate node locally, change host.docker.internal to the Substrate node's IP address)

docker run -p 8080:8080 -it --env-file=ei.env smartcontract/external-initiator "{\"name\":\"substrate-node\",\"type\":\"substrate\",\"url\":\"ws://host.docker.internal:9944/\"}"

Run Substrate Adapter

It is recommended to get familiar with the Substrate Adapter's run instructions before starting: https://github.com/smartcontractkit/substrate-adapter

  1. Install subkey

  2. Install dependencies: go get

  3. Build executable: go build -o substrate-adapter

  4. Set applicable environment variables, or run with env vars:

  5. Run

PORT=3000 SA_TX_TYPE=immortal SA_PRIVATE_KEY="<your-substrate-private-key>" SA_ENDPOINT="ws://host.docker.internal:9944/" ./substrate-adapter

Add Substrate Adapter to Chainlink node

  1. Access the Chainlink node GUI at http://localhost:6688/

  2. Head over to Bridges and create new

  3. Give it the name "substrate" and enter the URL the adapter is listening on

If running the adapter locally using the command provided above, this would be http://host.docker.internal:3000/

Add test jobspec

  1. Create new job in the CL node GUI with the following jobspec:
{
  "initiators": [
    {
      "type": "external",
      "params": {
        "name": "test-ei",
        "body": {
          "endpoint": "substrate-node",
          "accountIds": ["0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d","0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"]
        }
      }
    }
  ],
  "tasks": [
    {
      "type": "httpget"
    },
    {
      "type": "jsonparse"
    },
    {
      "type": "multiply"
    },
    {
      "type": "substrate",
      "params": {
        "type": "uint128"
      }
    }
  ]
}

Send a request on-chain

Follow instructions on how to run the front-end, then click the button to send a request.