Skip to content

Authenticating with the API

Thomas edited this page Aug 13, 2018 · 6 revisions

Starting with version 0.3.0, external resources (users, clients, operators, external adapters, etc.) wanting to access a node's API will need credentials in order to pass authentication. These credentials are first created by the node operator upon the first run of the node. The operator will be presented with a prompt asking for an email and password.

Enter API Email: 
Enter API Password:

The password does not need to be your email account's actual password, but will be used for authenticating with the node with the given email address (like a username).

With the node running after successfully creating an API account, you should see a log similar to the one below:

2018-07-21T11:14:23Z [INFO]  API exposed for user myaccount@api.com      cmd/local_client.go:48

You can now create a text file to store your API account information for automating the startup process of the node. The text file should be two lines, the first being the email address, and the second line being the password. For example:

myaccount@api.com
mypassword

Then when running the node, you can specify the -a option with the path to the API account text file. For example:

$ chainlink n -a /home/$USER/.chainlink/.api

Authenticating through the API

When creating requests from the node directly through the API, you will receive HTTP 401 errors so long as you are not including the session cookie file.

Using an example with curl you can create a cookie file like so:

curl -c cookiefile -X POST \
  -H 'Content-Type: application/json' \
  -d '{"email":"test@example.com", "password":"my_password"}'
   http://localhost:6688/sessions

You can then use the cookiefile created from the previous request to interact with the API:

curl -b cookiefile http://localhost:6688/v2/account_balance

Authenticating through the command-line

While the Chainlink node is running, you may receive the following error when trying to run chainlink commands, for example:

$ chainlink a
401 Unauthorized; Try logging in

The second terminal hasn't been authenticated with the API, so you will need to log in:

$ chainlink login
Enter email: myaccount@api.com
Enter password:
$ chainlink a
╔ Account Balance
╬════════════════════════════════════════════╬══════════════════════╬══════════════════════╬
║                  ADDRESS                   ║         ETH          ║         LINK         ║
╬════════════════════════════════════════════╬══════════════════════╬══════════════════════╬
║ 0xEABB718Fa7A688Fc28f40700551721114955ff64 ║ 0.000000000000000000 ║ 0.000000000000000000 ║
╬════════════════════════════════════════════╬══════════════════════╬══════════════════════╬

Authenticating through the GUI

With the node running, you can navigate to http://localhost:6688/ to view the admin dashboard. The connection may need HTTP or HTTPS depending on the value of CHAINLINK_DEV (true or false). Upon connecting, you will be presented with a sign-in page. Your username and password will be what you set up with the node, and upon successful authentication, you will be brought to the admin dashboard.