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.
- 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
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
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"
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:
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
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
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"
you can get ETH and LINK following these links:
you can start fulfilling requests following this chianlink tutorial
based on chainlink blog: Building and using External Adapters
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" } }'
2nd part of blog
- You need first to register in Openweathermap and get an API key.
- Create a
.env
file then add the API Key to itAPI_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"} }