Code Monkey home page Code Monkey logo

chainlink-poc-local's Introduction

Chainlink local

Local node

This proof of concept explains how to run a chainlink node on your computer. This should not be used as production environment but rather as an exercice to get familiar with chainlink concepts.

Prerequisites

  • Must have docker installed docker
  • Must have a connection to Ethereum , either using a local client or external provider. In my case, I'm using Infura

Run a Chainlink Node

Create a docker network bridge

We are going to run 2 containers:

  • One for Chainlink node
  • One for Postgresql

Chainlink node must be able to access postgresql container. By defualt, every container is isolated. Unless we define a network bridge and configure containers to use this network.

 docker network create cl-net

Run a local Postgresql database

We are running here the official postgres docker image. Note the user name is cl-node and password is cl-node-pass . we are also mounting a volume in order to persist data even if the container restarts

mkdir ./pg-data

docker run --name cl-postgres -e POSTGRES_DB=postgres -e POSTGRES_USER=cl-node --network cl-net -e POSTGRES_PASSWORD=cl-node-pass -e PGDATA=/var/lib/postgresql/data/pgdata \
-p 5432:5432 \
-v pg-data:/var/lib/postgresql/data \
-d postgres:13.3

Note that network is passed to the commande line --network cl-net

At this point, a postgres instance is running on your local machine on port 5432

you can check that the postgres image is running

docker ps

Command should display cl-postgres as "UP"

PG docker successful

Install a postgresql client

This is optional but you can install a postgresql client in order to view data that will be created. I'm using pgadmin

Once installed, you can create a new connection:

  • username : cl-node
  • database: postgres
  • password: cl-node-pass
  • server url: localhost
  • port: 5432

Once saved, connection should be sucessful and you'll be able to see your database as show below: DB succesful connection

Prepare environment files

Follow the steps Running a Chainlink Node

Remark: don't forget to mention "sslmode=disable" in the postgres connection string . For instance, if you chose to test on Rinkeby then your config should look like:

echo "DATABASE_URL=postgresql://cl-node:cl-node-pass@cl-postgres:5432/postgres?sslmode=disable" >> ~/.chainlink-rinkeby/.env

Note cl-postgres is the container name of postgres. As we will run chainlink container on the same network, "cl-postgres" will be resolved to an internal IP reachable by chainlink container

Run Chainlink node

When running the chainlink node, do not forget to specify the network so that chainlink node is able to call Postgres container. Your command should look like the following:

cd ~/.chainlink-rinkeby && docker run --name chainlink -p 6688:6688 --network cl-net -v ~/.chainlink-rinkeby:/chainlink -it --env-file=.env smartcontract/chainlink:0.10.8 local n -p /chainlink/.password -a /chainlink/.api

Now running docker ps should display 2 containers

Chainlink docker successful

Import account in Metamask

sometimes it could be interesting to view the account in metamask and be able to check the funds. To do so, please follow these steps:

  • exec inside your container docker exec -it chainlink bash
  • go inside the host mounted folder cd /chainlink
  • login using username and password that was set in ".api" files (cfr. Running a Chainlink Node) : chainlink admin login
  • you can view imported accounts using: chainlink keys eth list
  • you can export the node account key using the password that was set in ".password" file (cfr. Running a Chainlink Node) chainlink keys eth export 0xCD5f012fdFFf3d653085e5A41a7F9356A0D0b733 -p .password --output key.json
  • on the host machine, you should find "key.json" in "~/.chainlink-rinkeby" (If you are using rinkeby for your tests)
  • you can import "key.json" in metamask. If will ask you for a password, you can use the password that was set in ".password"

Fund the node account

you can get ETH and LINK following these links:

  • LINK
  • list of ETH faucets per environment could be found here: ETH

Test the node

you can start fulfilling requests following this chianlink tutorial

Chainlink external adapter

based on chainlink blog: Building and using External Adapters

How to build an externa adapter

1st part of blog

cd external-adapter/eth-price
yarn
yarn start

in another terminal , you should get a succesful reponse if you run curl -X POST -H "content-type:application/json" "http://localhost:8080/" --data '{ "id": 0, "data": { "from": "ETH", "to": "USD" } }'

Getting Weather Data

2nd part of blog

  • You need first to register in Openweathermap and get an API key.
  • Create a .envfile then add the API Key to it API_KEY=<YOUR_API_KEY>
cd external-adapter/weather
yarn
yart start

in another terminal , you should get a succesful reponse if you run curl -X POST -H "content-type:application/json" "http://localhost:8080/" --data '{ "id": 0, "data": { "city": "Boston"} }

chainlink-poc-local's People

Contributors

aelmanaa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.