Introduction
This is a tutorial on how to set up and run a Chainlink node working with an Ethereum node deployed with Chainstack.
For tutorial purposes:
- This guide walks you through running a Chainlink node on the Ropsten testnet.
- The Chainlink node will run in Docker on Ubuntu.
- The PostgreSQL database will also run on Ubuntu.
See also Chainlink Docs: Running a Chainlink Node.
Step-by-step
Install Docker
Run:
curl -sSL https://get.docker.com/ | sh
See also: Get Docker.
Set up your Chainlink directory with the .env file
Create the directory:
mkdir ~/.chainlink-ropsten
Create the .env file:
echo "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=*" > ~/.chainlink-ropsten/.env
Note that ETH_CHAIN_ID is set to 3 as this is the Ropsten testnet.
Deploy a Ropsten testnet node with Chainstack
Deploy the node as described in Join a public network.
Get the WSS endpoint and access credentials of your deployed node as described in View node access and credentials.
Add the Ropsten testnet node to the .env file
Run:
echo "ETH_URL=WSS_ENDPOINT" >> ~/.chainlink-ropsten/.env
where
- USERNAME — your Ropsten node access username.
- PASSWORD — your Ropsten node access password.
- WSS_ENDPOINT — your Ropsten node WSS endpoint.
Example:
echo "ETH_URL=https://nd-123-456-789.p2pify.com/3c6e0b8a9c15224a8228b9a98ca1531" >> ~/.chainlink-ropsten/.env
Set up a PostgreSQL database
Install PostgreSQL:
sudo apt-get install postgresql postgresql-contrib
Switch to the postgres user:
su - postgres
Create a database user that you will use to connect to the PostgreSQL database from the Chainlink node:
createuser --interactive --pwprompt
In the create user wizard, provide a user name and a password.
On the Shall the new role be a superuser? (y/n) prompt, type y.
Example:
# createuser --interactive --pwprompt
Enter name of role to add: chainlinkuser
Enter password for new role:
Confirm password:
Shall the new role be a superuser? (y/n) y
Create a database for the user that you just created:
createdb -O SUPERUSER DATABASE_NAME
where
- SUPERUSER — the PostgreSQL database superuser you created.
- DATABASE_NAME — any database name.
Example:
createdb -O chainlinkuser chainlinkdatabase
Allow connections to the PostreSQL database by editing the postgresql.conf file:
nano /etc/postgresql/10/main/postgresql.conf
In the editor, uncomment the listen_addresses line and set it to any:
listen_addresses = '*'
Allow connections to the PostreSQL database by editing the pg_hba.conf file:
nano /etc/postgresql/10/main/pg_hba.conf
In the editor, add the following line at the end of the file:
host all all 0.0.0.0/0 md5
Exit back to your root user:
exit
Restart your PostreSQL instance for the changes to take effect:
sudo systemctl restart postgresql
Add the PostreSQL URL to the .env file
Run:
echo "DATABASE_URL=postgresql://SUPERUSER:PASSWORD@IP_ADDRESS:PORT/DATABASE_NAME" >> ~/.chainlink-ropsten/.env
where
- SUPERUSER — the PostgreSQL database superuser you created.
- PASSWORD — the password for the superuser.
- IP_ADDRESS — the IP address of the machine where you run your PostgreSQL database.
- PORT — use the default PostgreSQL port 5432.
- DATABASE_NAME — the database name you previously set up.
Example:
echo "DATABASE_URL=postgresql://chainlinkuser:123456@164.90.181.176:5432/chainlinkdatabase" >> ~/.chainlink-ropsten/.env
Run the Chainlink node
Run:
cd ~/.chainlink-ropsten && docker run -p 6688:6688 -v ~/.chainlink-ropsten:/chainlink -it --env-file=.env smartcontract/chainlink local n
This will start the Chainlink node, connect to the Ropsten node, and connect to the PostgreSQL database.
You will be prompted to:
- Create a password for your Chainlink wallet.
- Enter an email and create a password to access your Chainlink node instance.
Access the running Chainlink node in the UI
You can now access your node at http://IP_ADDRESS:6688/.
Example:
If you have any questions, feel free to contact Chainstack support by emailing support@chainstack.com or by submitting this form.
Comments
0 comments
Please sign in to leave a comment.