thodges-gh / CL-EA-NodeJS-Template

61 stars 70 forks source link

Chainlink NodeJS External Adapter Template

This template provides a basic framework for developing Chainlink external adapters in NodeJS. Comments are included to assist with development and testing of the external adapter. Once the API-specific values (like query parameters and API key authentication) have been added to the adapter, it is very easy to add some tests to verify that the data will be correctly formatted when returned to the Chainlink node. There is no need to use any additional frameworks or to run a Chainlink node in order to test the adapter.

Creating your own adapter from this template

Clone this repo and change "ExternalAdapterProject" below to the name of your project

git clone https://github.com/thodges-gh/CL-EA-NodeJS-Template.git ExternalAdapterProject

Enter into the newly-created directory

cd ExternalAdapterProject

You can remove the existing git history by running:

rm -rf .git

See Install Locally for a quickstart

Input Params

Output

{
 "jobRunID": "278c97ffadb54a5bbb93cfec5f7b5503",
 "data": {
  "USD": 164.02,
  "result": 164.02
 },
 "statusCode": 200
}

Install Locally

Install dependencies:

yarn

Test

Run the local tests:

yarn test

Natively run the application (defaults to port 8080):

Run

yarn start

Call the external adapter/API server

curl -X POST -H "content-type:application/json" "http://localhost:8080/" --data '{ "id": 0, "data": { "from": "ETH", "to": "USD" } }'

Docker

If you wish to use Docker to run the adapter, you can build the image by running the following command:

docker build . -t external-adapter

Then run it with:

docker run -p 8080:8080 -it external-adapter:latest

Serverless hosts

After installing locally:

Create the zip

zip -r external-adapter.zip .

Install to AWS Lambda

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.

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.

Install to GCP