• Stars
    star
    270
  • Rank 152,189 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 24 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Monorepo containing JavaScript implementation of external adapters

Chainlink External Adapters (TypeScript)

This repository contains the source code for Chainlink external adapters. If you would like to contribute, please see the Contributing page for more details.

Table of Contents

  1. Getting Started
  2. How to Run
  3. Testing
  4. Deployment
  5. EA Versioning
  6. Advanced Features

Getting Started

Requirements

  • Node.js v16
  • Yarn

Install

yarn

Installs the dependencies for all workspaces.

Setup

yarn setup

Runs the setup step for all adapters. Typically this step just compiles TypeScript, but may involve other tasks.

Clean

yarn clean

Clears all build files/directories. Useful in case of issues when installing dependencies or running setup.

Folder Structure

╠═.github - scripts automatically ran by the CI/CD workflow
β•‘
╠═.husky - git hooks
β•‘
╠═.vscode - code editor specific configuration
β•‘
╠═.yarn - yarn 2 dependencies
β•‘
β•šβ•packages
    β•‘
    ╠══ composites - adapters composed of multiple other adapters for complex functionality
    β•‘
    ╠══ core - the internal framework used across all external adapters
    β•‘
    ╠══ examples - example templates for new external adapters
    β•‘
    ╠══ scripts - additional Node.js scripts for mono-repository management
    β•‘
    ╠══ sources - adapters that read data from a data provider's API.
    β•‘
    β•šβ•β• targets - adapters that write data to a location, often a blockchain.

How to Run

External adapters should be run as long-lived processes, either directly as HTTP Server, Docker Container, or Single-Command Docker App. Each adapter may have configuration that is required to be supplied through environment variables.

Configuration

There may be required environment variables that must be provided to run an External Adapter. Please see the respective adapter's README for more specific information on the External Adapter that you would like to run.

Every External Adapter has some optional environment variables for customizing behavior and turning on advanced features. More documentation for these can be seen here.

Run as HTTP server

Use the start command while in the directory of the adapter that you would like to run. For example:

cd packages/sources/coingecko
yarn start

Run as Docker Container

  1. All of the external-adapters have a service that is created when the repo's docker-compose file is generated.

This can be done by running the following command in the root of the repository (after yarn && yarn setup):

yarn generate:docker-compose
  1. Next create a container image. Use the generated docker-compose.generated.yaml file along with docker-compose build.
docker-compose -f docker-compose.generated.yaml build [adapter-name]

Where [adapter-name] is replaced with the following:

Parameter Description Options
adapter-name name of the external adapter package, usually the folder name with -adapter as a suffix See docker-compose.generated.yaml for list of services that can be used as options

For example the bravenewcoin external adapter uses bravenewcoin-adapter:

docker-compose -f docker-compose.generated.yaml build bravenewcoin-adapter
  1. Then run it with:
docker-compose -f docker-compose.generated.yaml run -p 8080:8080 -e API_KEY='YOUR_API_KEY' bravenewcoin-adapter

Environment files can also be passed through a file:

docker run -p 8080:8080 --env-file="~/PATH_TO_ENV" -it proof-of-reserves-adapter:latest

Single-Command Docker App

This command will start all of your external adapters with performance features enabled and with pre-defined metrics charts for each EA on a single server.

The first step will be to load up all of the environment variables that are needed across all of the External Adapters that will be ran. These can either be already be loaded into the environment or supplied to the startup script as a text file. Also make sure that Grafana dependencies are installed.

Starting from the root of the repository:

  1. Ensure that the project is setup and that the docker-compose file has been generated
yarn && yarn setup && yarn generate:docker-compose
  1. Use the startup script by supplying every External Adapter that you would like to run and monitor.

The adapter will have the format of [[ADAPTER NAME]]-adapter.

For example:

cd grafana && ./scripts/compose.sh coingecko-adapter coinmarketcap-adapter
  1. The running services can be found at the following ports:
  • External Adapters - search docker-compose.generated.yaml for the name of your EA. The port it is running on will be found as the first number before the colon under ports.
coincodex-adapter:
  image: coincodex-adapter:0.0.4
  ports:
    - 8112:8080 <----------- The first number before the colon here
  build:
    context: ..
    dockerfile: ./Dockerfile
    args:
      location: packages/sources/coincodex
      package: '@chainlink/coincodex-adapter'
    labels:
      com.chainlinklabs.external-adapter-type: sources
  environment:
    - EA_PORT=${EA_PORT}

Testing

In order to test adapters locally, you may need to set environment variables such as $API_KEY. These can be found in the README.md for every adapter.

When running integration tests make sure that metrics are disabled (export METRICS_ENABLED=false) and EA server is running on random available port (export EA_PORT=0).

Make sure you run these commands from the ROOT of this monorepo.

# Build all packages
yarn setup

# Run all unit tests
yarn test:unit

# Run all integration tests
yarn test:integration

export adapter=myadapter # Your adapter name, coinmarketcap, coingecko, etc

# Run integration tests for that adapter
yarn test $adapter/test/integration

# Run unit tests for that adapter
yarn test $adapter/test/unit

# Run a specific test for that adapter
yarn test $adapter/test/unit/my-specific-test.test.ts

# Run a tests in watch mode, re-running tests that have code changes or dependency changes in them
yarn test --watch $adapter/test/unit

Deployment

Container Images

Images are being published to Chainlink's public AWS ECR repositories: public.ecr.aws/chainlink/adapters

They can also be found in the public gallery, the registry name is chainlink (e.g. https://gallery.ecr.aws/chainlink/adapters/1forge-adapter).

The External Adapters are being tagged with semantic releases to allow for automated upgrades.

Running from ECR

The EA container image can be download by using the docker pull command. For example:

docker pull public.ecr.aws/chainlink/adapters/1forge-adapter:latest

To run the image use the docker run command. For example:

docker run -p 8080:8080 -e API_KEY='YOUR_API_KEY' public.ecr.aws/chainlink/adapters/1forge-adapter:latest

It can be helpful to pass a text file to the container to handle giving multiple environment variables:

docker run -p 8080:8080 --env-file=[[path to your env file]] public.ecr.aws/chainlink/adapters/1forge-adapter:latest

External Adapters Versioning

For a full rundown on how versioning works, see semver.

What you need to know is that we make releases with the following versioning scheme: major.minor.patch.

  • A patch version change usually has small changes/bug fixes. Upgrading/downgrading the patch version number should never break compatibility.
  • A minor version change usually adds functionality. Upgrading should never break compatibility, but you might not be able to downgrade the minor version.
  • A major version change usually introduces a breaking change. Both upgrading and downgrading the major version number might require additional work. Proceed with caution!

Best practice is to try to always keep it up to date!

Why do the versions jump up sometimes?

Sometimes when looking at the releases for an EA you might see it jumped a version number. For example, the previous release might be 1.2.3 and then the next release is 1.2.5. The reason being is that each week we publish a new release. Whenever we make a change it includes a changeset, which uses versioning semantics above (major, minor, and patch). Sometimes over the course of a given week, more than one changes are included in an adapter, so more than one changeset gets ingested into the release, thus causing the release number to jump. So if a version went from 1.2.3 to 1.2.5, that means two patches were pushed that week.

Advanced Features

Performance and Caching

The following section details mechanisms that reduce the number of API calls made from external adapters. It is highly recommended to turn on the following three middlewares.

Caching

Caching allows for the EA to store successful responses and facilitate faster future response times. See here for more information.

⚠️ Note

Please check and ensure caching is allowed and not in violation of the Terms of Service of the data provider's API. Disable caching flags if it is not supported by the specified API provider's TOS.

Caching is enabled by default. It can be turned off using:

export CACHE_ENABLED=false

Rate Limiting

The Rate Limit middleware prevents hitting rate limit issues with data providers. This is done by adjusting how long a request lives in the cache based on the available capacity of your API subscription plan. The cache must be enabled to use this middleware. See here for more information.

Rate Limiting is enabled by default. It can be turned off using:

export RATE_LIMIT_ENABLED=false

There are two options for defining API subscription capacity:

  1. Manual setting (example shown for limit at 10 requests/minute)
export RATE_LIMIT_CAPACITY=60
  1. Limits by provider data (example for Coingecko free tier)
export RATE_LIMIT_API_PROVIDER=coingecko RATE_LIMIT_API_TIER=free

The RATE_LIMIT_API_PROVIDER environment variable is optional as when not given it will derive from the running adapter.

Preset tiers/plans can be found here and use the corresponding provider and tierName.

Cache Warming

When a new unique request comes in to an EA the Cache Warming middleware will begin polling the API on an interval ensure that data is always ready to be served and is as fresh as possible. The cache must be enabled to use this middleware. See here for more information.

Cache Warming is enabled by default. It can be turned off using:

export WARMUP_ENABLED=false

The cache will begin polling once the first request has been received. It will also attempt to use batch requests to save API credits when possible.

Multiple API Key Support

In order to use multiple API keys for an adapter, simply comma delimit the keys where you define the environment variable. This will work for an arbitrary number of keys.

export API_KEY=myapikey1,myapikey2,myapikey3

The external adapter will then randomly rotate the keys. Over time this should balance out the number of requests between each of the API keys.

Bridge URL Query String Parameters

Additional input parameters can be passed to an External Adapter through the Bridge URL that is specified when connecting an External Adapter to the core node.

This is useful in scenarios where when running multiple External Adapters to service a job spec there is a single External Adapter's behavior needs to be customized without affecting the others.

Ticker Overrides

There are cases where a certain data provider might have different ticker symbol to represent a cryptocurrency, often when there are multiple cryptocurrencies that share the same ticker.

To help query the correct symbols the External Adapter request can contain an object of symbol overrides named overrides:

"overrides": {
      "coinmarketcap": {
        "RAI": "RAI2"
      }
    },

In the above example when the coinmarketcap External Adapter is requested with a base of RAI the ticker will be changed to RAI2.

More Repositories

1

full-blockchain-solidity-course-js

Learn Blockchain, Solidity, and Full Stack Web3 Development with Javascript
12,549
star
2

full-blockchain-solidity-course-py

Ultimate Solidity, Blockchain, and Smart Contract - Beginner to Expert Full Course | Python Edition
10,703
star
3

chainlink

node of the decentralized oracle network, bridging on and off-chain computation
Go
6,990
star
4

hardhat-starter-kit

A repo for boilerplate code for testing, deploying, and shipping chainlink solidity code.
JavaScript
1,203
star
5

chainlink-mix

Working with smart contracts with eth-brownie, python, and Chainlink.
Solidity
484
star
6

defi-minimal

This repo is dedicated to making minimal repos of existing defi primatives.
JavaScript
473
star
7

documentation

https://docs.chain.link The Chainlink developer documentation website for Smart Contract Devs and Node Operators
MDX
406
star
8

foundry-starter-kit

Solidity
331
star
9

truffle-starter-kit

An example smart contract utilizing Chainlink
JavaScript
258
star
10

starter-kits

A repo of starter kits for working with various languages and frameworks across the smart contract ecosystem.
238
star
11

foundry-starter-kit-old

Solidity
204
star
12

smart-contract-examples

Example and sample projects
Solidity
188
star
13

solana-starter-kit

Example code for using Chainlink on Solana
JavaScript
172
star
14

chainlink-brownie-contracts

A repository for automatically using the latest chainlink repo from the core chainlink repo.
Solidity
168
star
15

chainlink-ruby

Easily connect your applications to blockchains
Ruby
157
star
16

Web3_tutorial_Chinese

Solidity
152
star
17

functions-hardhat-starter-kit

JavaScript
148
star
18

chainlink-polkadot

Go
139
star
19

LinkToken

LINK Token Contracts for the Chainlink Network
Solidity
132
star
20

ccip

Cross Chain Interoperability Protocol
Go
122
star
21

huff-starter-kit

A template repo to work with huff smart contracts and learn about low level EVM opcodes. Also Horse β™˜.
Solidity
101
star
22

apeworx-starter-kit

A repo dedicated to showing how to make smart contracts in a purely pythonic environment
Python
90
star
23

chainlink-solana

Go
81
star
24

blockchain-developer-hub

Dive into blockchain and smart contract development.
JavaScript
80
star
25

ccip-starter-kit-foundry

This project demonstrates a couple of basic Chainlink CCIP use cases
Solidity
75
star
26

chainlink-fullstack

Full stack starter project showcasing Chainlink products on Ethereum (EVM)
TypeScript
68
star
27

libocr

libocr consists of a Go library and a set of Solidity smart contracts that implement the Chainlink Offchain Reporting Protocol
Go
68
star
28

hardhat-chainlink

Integrates Chainlink into Hardhat projects. This package is currently in the BETA testing phase and is not recommended for production usage yet.
TypeScript
65
star
29

solidity-cborutils

A library for encoding CBOR in Solidity.
Solidity
64
star
30

dapptools-starter-kit

Solidity
63
star
31

ccip-cross-chain-nft

This project demonstrates how to mint an NFT on one blockchain from another blockchain using Chainlink CCIP
Solidity
62
star
32

ccip-read

TypeScript
60
star
33

chainlink-testing-framework

A testing framework for smart contracts and Chainlink nodes
Go
60
star
34

foundry-chainlink-toolkit

A plugin to use Chainlink products/services in Foundry
Solidity
59
star
35

chainlink-starknet

Go
58
star
36

ccip-starter-kit-hardhat

This project demonstrates a couple of basic Chainlink CCIP use cases
TypeScript
58
star
37

prediction-game

Rugby prediction game using Chainlink Functions, Automation, and CCIP.
TypeScript
56
star
38

chainlink-local

The Chainlink CCIP Local Simulator, visit documentation by clicking the link below:
Solidity
49
star
39

ccip-defi-lending

CCIP Launch Defi Demo
JavaScript
46
star
40

smart-contract-db

This repository is an archive. This project has been superseded by blockchain.education https://github.com/smartcontractkit/blockchain-developer-hub
TypeScript
44
star
41

external-initiator

Initiate Chainlink job runs from external sources
Go
39
star
42

chainlink-solana-demo

Showing how to deploy a Solana program using Chainlink Price Feeds
TypeScript
37
star
43

chainlink-automation-templates

Real-world sample projects using Chainlink Automation
Solidity
35
star
44

usechainlinkfunctions

TypeScript
31
star
45

functions-toolkit

An NPM package with collection of tools that can be used for working with Chainlink Functions.
TypeScript
26
star
46

near-protocol-contracts

Rust
26
star
47

chainlink-common

SDK for building Chainlink Services and Plugins
Go
25
star
48

chainlink-cosmos

Go
25
star
49

env-enc

TypeScript
25
star
50

ccip-cross-chain-name-service

This project is an educational example of how to create a minimal cross-chain name service using Chainlink CCIP
TypeScript
25
star
51

functions-deepdive-constellation2023

Deepdive Workshop For Constellation 2023 Hackathon
JavaScript
24
star
52

run-functions-dapp

Demo dApp using Chainlink Functions to bring web2 data on-chain.
TypeScript
24
star
53

wasp

Protocol-agnostic load testing library for Go
Go
24
star
54

devnet

An Ethereum development network with preset configs for easy testing.
Makefile
22
star
55

Blockchain-RPC-Exporter

Prometheus exporter for EVM compatible RPC endpoints.
Python
20
star
56

ccip-owner-contracts

A set of smart contracts used for administering Chainlink contracts, most notably CCIP
Solidity
18
star
57

chainlink-functions-demo-app

TypeScript
18
star
58

schemas

specification for offering and requesting off-blockchain services
17
star
59

paypal-adapter

TypeScript
17
star
60

chainlink-github-actions

Common action to run chainlink-testing-framework based tests in github ci
TypeScript
16
star
61

risk-management-network

Rust
16
star
62

wei_watchers

A service for push notifications of Ethereum logs and account balances.
Ruby
15
star
63

chain-selectors

Go
15
star
64

arbitrum-quickstart

JavaScript
14
star
65

ccip-tic-tac-toe

TypeScript
14
star
66

solc-api

minimal Solidity compiler service
JavaScript
14
star
67

chainlink-env

Chainlink k8s environment library
Go
14
star
68

datastreams-demo

Demo dApp using Chainlink Data Streams.
TypeScript
13
star
69

operator-ui

TypeScript
13
star
70

hello_chainlink

chainlink demos
JavaScript
12
star
71

chainlink-staking-v0.2-public-guide

12
star
72

wsrpc

A bi-directional Websockets RPC library
Go
12
star
73

quickstarts-historical-prices-api

TypeScript
12
star
74

functions-lens-eventbrite

Solidity
12
star
75

tdh2

An implementation of the TDH2 protocol by Shoup & Gennaro (paper link https://www.shoup.net/papers/thresh1.pdf)
Go
11
star
76

chainlink-RSK

Solidity
11
star
77

functions-the-graph-uniswap

Solidity
11
star
78

rwa-tokenization

TypeScript
11
star
79

chainlink-automation

Go
10
star
80

chainlink-data-streams

Go
10
star
81

workshop-distributed-news

Solidity
10
star
82

solana-prediction-game

JavaScript
10
star
83

builder

A docker build file for chainlink
Dockerfile
10
star
84

chainlink-vrf

OCR2VRF (in development, do not use in production)
Go
10
star
85

ccip-liquidation-protector

This project demonstrates how to automate preventing DeFi liquidations & optimizing interest rates on multiple blockchains using Chainlink CCIP, Chainlink Automation and Chainlink Functions
TypeScript
10
star
86

cairo-starter-kit

The boilerplate code for getting started with the usage of Chainlink services on Starknet
TypeScript
9
star
87

ea-framework-js

TypeScript
9
star
88

hardhat-network

Deploys a basic hardhat chain for testing
Dockerfile
9
star
89

bq-example-contract

JavaScript
8
star
90

.github

TypeScript
8
star
91

chainlink-node-compose

Docker Compose script for launching multiple chainlink nodes
Shell
8
star
92

substrate-adapter

Go
7
star
93

link-token-sidechain-evm

LINK Token On EVM Sidechains
Solidity
7
star
94

push-gha-metrics-action

Shell
7
star
95

DEVREL-collaborative-nft-tutorial

Solidity
7
star
96

blockchain-ecosystem-map

JavaScript
7
star
97

timelock-worker

Daemon to poll and execute scheduled transactions from a Timelock contract.
Go
7
star
98

chainlink-solhint-rules

CLL custom Solhint rules
JavaScript
7
star
99

functions-google-bigquery

Demonstration of accessing data from Google BigQuery via Chainlink Functions
JavaScript
6
star
100

chainlink-terra-feeds-demo

Showing how to deploy a Terra smart contract which utilizes Chainlink Data Feeds
Rust
6
star