1. Home
  2. Docs
  3. Chainlink Adapters
  4. Adapter Monorepo

Adapter Monorepo

JavaScript implementation of external adapters

GITHUB: https://github.com/smartcontractkit/external-adapters-js

This repository contains the source for Chainlink external adapters. Each adapter must document its own required parameters and output format.

Download:
$ sudo git clone https://github.com/smartcontractkit/external-adapters-js

$ cd external-adapters-js

Install:
sudo yarn install

Test: (In order to test adapters locally, you may need to set an $API_KEY environment variable for the given API.)

$ cd cryptocompare

$ yarn test
(replace cryptocompare with adapter you want to install)

Docker:
From root directory use command to build a Docker container for cryptocompare.
$ make docker adapter=cryptocompare

Open Firewall Ports to run Container
$ sudo ufw allow 8080

Run Docker Container.
$ sudo docker run –name cryptocompare -p 8080:8080 -e API_KEY=’YOUR_API_KEY’ -it cryptocompare-adapter:latest

Serverless:
$ make zip adapter=cryptocompare
(The zip will be created as ./$adapter/dist/$adapter-adapter.zip.)

AWS Lambda:
In Lambda Functions, create function
On the Create function page: Give the function a name
Use Node.js 12.x for the runtime
Choose an existing role or create a new one
Click Create Function
Under Function code, select “Upload a .zip file” from the Code entry type drop-down
Click Upload and select the $adapter-adapter.zip file
Handler: index.handler for REST API Gateways
index.handlerv2 for HTTP API GatewaysBy default, Lambda functions time out after 3 seconds. You may want to change that to 60s in case an API takes longer than expected to respond.

To Set Up an API Gateway (HTTP API)
If using a HTTP API Gateway, Lambda’s built-in Test will fail, but you will be able to externally call the function successfully.
Click Add Trigger
Select API Gateway in Trigger configuration
Under API, click Create an API
Choose HTTP API
Select the security for the API
Click Add

To Set Up an API Gateway (REST API)
If using a REST API Gateway, you will need to disable the Lambda proxy integration for Lambda-based adapter to function.
Click Add Trigger
Select API Gateway in Trigger configuration
Under API, click Create an API
Choose REST API
Select the security for the API
Click Add
Click the API Gateway trigger
Click the name of the trigger (this is a link, a new window opens)
Click Integration Request
Uncheck Use Lamba Proxy integration
Click OK on the two dialogs
Return to your function
Remove the API Gateway and Save
Click Add Trigger and use the same API Gateway
Select the deployment stage and security
Click Add
Add the environment variable (repeat for all environment variables): Key: API_KEY
Value: Your_API_key
Save

GCP:
In Functions, create a new function, choose to ZIP upload
Select Node.js 10 for the Runtime
Click Browse and select the $adapter-adapter.zip file
Select a Storage Bucket to keep the zip in
Function to execute: gcpservice
Click More, Add variable (repeat for all environment variables) NAME: API_KEY
VALUE: Your_API_key

How To Create New External Adapter:
Run the command below to have the example directory cloned.

$ make new adapter=my-adapter-name

(If on a Mac, this requires gnu-sed to be installed and set as the default for the command sed.)

Was this article helpful to you? Yes No

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *