• Stars
    star
    6,970
  • Rank 5,594 (Top 0.2 %)
  • Language
    Go
  • License
    Other
  • Created almost 7 years ago
  • Updated 12 days ago

Reviews

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

Repository Details

node of the decentralized oracle network, bridging on and off-chain computation

Chainlink logo


GitHub tag (latest SemVer) GitHub license GitHub workflow changelog GitHub contributors GitHub commit activity Official documentation

Chainlink expands the capabilities of smart contracts by enabling access to real-world data and off-chain computation while maintaining the security and reliability guarantees inherent to blockchain technology.

This repo contains the Chainlink core node and contracts. The core node is the bundled binary available to be run by node operators participating in a decentralized oracle network. All major release versions have pre-built docker images available for download from the Chainlink dockerhub. If you are interested in contributing please see our contribution guidelines. If you are here to report a bug or request a feature, please check currently open Issues. For more information about how to get started with Chainlink, check our official documentation. Resources for Solidity developers can be found in the Chainlink Hardhat Box.

Community

Chainlink has an active and ever growing community. Discord is the primary communication channel used for day to day communication, answering development questions, and aggregating Chainlink related content. Take a look at the community docs for more information regarding Chainlink social accounts, news, and networking.

Build Chainlink

  1. Install Go 1.20, and add your GOPATH's bin directory to your PATH
    • Example Path for macOS export PATH=$GOPATH/bin:$PATH & export GOPATH=/Users/$USER/go
  2. Install NodeJS v16 & pnpm via npm.
    • It might be easier long term to use nvm to switch between node versions for different projects. For example, assuming $NODE_VERSION was set to a valid version of NodeJS, you could run: nvm install $NODE_VERSION && nvm use $NODE_VERSION
  3. Install Postgres (>= 11.x and <= 15.x).
    • You should configure Postgres to use SSL connection (or for testing you can set ?sslmode=disable in your Postgres query string).
  4. Ensure you have Python 3 installed (this is required by solc-select which is needed to compile solidity contracts)
  5. Download Chainlink: git clone https://github.com/smartcontractkit/chainlink && cd chainlink
  6. Build and install Chainlink: make install
  7. Run the node: chainlink help

For the latest information on setting up a development environment, see the Development Setup Guide.

Apple Silicon - ARM64

Native builds on the Apple Silicon should work out of the box, but the Docker image requires more consideration.

$ docker build . -t chainlink-develop:latest -f ./core/chainlink.Dockerfile

Ethereum Execution Client Requirements

In order to run the Chainlink node you must have access to a running Ethereum node with an open websocket connection. Any Ethereum based network will work once you've configured the chain ID. Ethereum node versions currently tested and supported:

[Officially supported]

[Supported but broken] These clients are supported by Chainlink, but have bugs that prevent Chainlink from working reliably on these execution clients.

We cannot recommend specific version numbers for ethereum nodes since the software is being continually updated, but you should usually try to run the latest version available.

Running a local Chainlink node

NOTE: By default, chainlink will run in TLS mode. For local development you can disable this by using a dev build using make chainlink-dev and setting the TOML fields:

[WebServer]
SecureCookies = false
TLS.HTTPSPort = 0

[Insecure]
DevWebServer = true

Alternatively, you can generate self signed certificates using tools/bin/self-signed-certs or manually.

To start your Chainlink node, simply run:

chainlink node start

By default this will start on port 6688. You should be able to access the UI at http://localhost:6688/.

Chainlink provides a remote CLI client as well as a UI. Once your node has started, you can open a new terminal window to use the CLI. You will need to log in to authorize the client first:

chainlink admin login

(You can also set ADMIN_CREDENTIALS_FILE=/path/to/credentials/file in future if you like, to avoid having to login again).

Now you can view your current jobs with:

chainlink jobs list

To find out more about the Chainlink CLI, you can always run chainlink help.

Check out the doc pages on Jobs to learn more about how to create Jobs.

Configuration

Node configuration is managed by a combination of environment variables and direct setting via API/UI/CLI.

Check the official documentation for more information on how to configure your node.

External Adapters

External adapters are what make Chainlink easily extensible, providing simple integration of custom computations and specialized APIs. A Chainlink node communicates with external adapters via a simple REST API.

For more information on creating and using external adapters, please see our external adapters page.

Development

Running tests

  1. Install pnpm via npm

  2. Install gencodec and jq to be able to run go generate ./... and make abigen

  3. Install mockery

make mockery

Using the make command will install the correct version.

  1. Build contracts:
pushd contracts
pnpm i
pnpm compile:native
popd
  1. Generate and compile static assets:
go generate ./...
  1. Prepare your development environment:
export CL_DATABASE_URL=postgresql://127.0.0.1:5432/chainlink_test?sslmode=disable

Note: Other environment variables should not be set for all tests to pass

  1. Drop/Create test database and run migrations:
make testdb

If you do end up modifying the migrations for the database, you will need to rerun

  1. Run tests:
go test -tags test ./...

Notes

  • The parallel flag can be used to limit CPU usage, for running tests in the background (-parallel=4) - the default is GOMAXPROCS
  • The p flag can be used to limit the number of packages tested concurrently, if they are interferring with one another (-p=1)
  • The -short flag skips tests which depend on the database, for quickly spot checking simpler tests in around one minute

Race Detector

As of Go 1.1, the runtime includes a data race detector, enabled with the -race flag. This is used in CI via the tools/bin/go_core_race_tests script. If the action detects a race, the artifact on the summary page will include race.* files with detailed stack traces.

It will not issue false positives, so take its warnings seriously.

For local, targeted race detection, you can run:

GORACE="log_path=$PWD/race" go test -race ./core/path/to/pkg -count 10
GORACE="log_path=$PWD/race" go test -race ./core/path/to/pkg -count 100 -run TestFooBar/sub_test

https://go.dev/doc/articles/race_detector

Fuzz tests

As of Go 1.18, fuzz tests func FuzzXXX(*testing.F) are included as part of the normal test suite, so existing cases are executed with go test.

Additionally, you can run active fuzzing to search for new cases:

go test ./pkg/path -run=XXX -fuzz=FuzzTestName

https://go.dev/doc/fuzz/

Go Modules

This repository contains three Go modules:

flowchart RL
    github.com/smartcontractkit/chainlink/v2
    github.com/smartcontractkit/chainlink/integration-tests --> github.com/smartcontractkit/chainlink/v2
    github.com/smartcontractkit/chainlink/core/scripts --> github.com/smartcontractkit/chainlink/v2

The integration-tests and core/scripts modules import the root module using a relative replace in their go.mod files, so dependency changes in the root go.mod often require changes in those modules as well. After making a change, go mod tidy can be run on all three modules using:

make gomodtidy

Solidity

Inside the contracts/ directory:

  1. Install dependencies:
pnpm i
  1. Run tests:
pnpm test

NOTE: Chainlink is currently in the process of migrating to Foundry and contains both Foundry and Hardhat tests in some versions. More information can be found here: Chainlink Foundry Documentation. Any 't.sol' files associated with Foundry tests, contained within the src directories will be ignored by Hardhat.

Code Generation

Go generate is used to generate mocks in this project. Mocks are generated with mockery and live in core/internal/mocks.

Nix

A shell.nix is provided for use with the Nix package manager, with optional flakes support. It defines a declarative, reproducible development environment. Flakes version use deterministic, frozen (flake.lock) dependencies, while non-flakes shell will use your channel's packages versions.

To use it:

  1. Install nix package manager in your system.
  1. Run nix-shell. You will be put in shell containing all the dependencies.
  • To use the flakes version, run nix develop instead of nix-shell. Optionally, nix develop --command $SHELL will make use of your current shell instead of the default (bash).
  • You can use direnv to enable it automatically when cd-ing into the folder; for that, enable nix-direnv and use nix or use flake on it.
  1. Create a local postgres database:
mkdir -p $PGDATA && cd $PGDATA/
initdb
pg_ctl -l postgres.log -o "--unix_socket_directories='$PWD'" start
createdb chainlink_test -h localhost
createuser --superuser --password chainlink -h localhost
# then type a test password, e.g.: chainlink, and set it in shell.nix CL_DATABASE_URL
  1. When re-entering project, you can restart postgres: cd $PGDATA; pg_ctl -l postgres.log -o "--unix_socket_directories='$PWD'" start Now you can run tests or compile code as usual.
  2. When you're done, stop it: cd $PGDATA; pg_ctl -o "--unix_socket_directories='$PWD'" stop

Tips

For more tips on how to build and test Chainlink, see our development tips page.

Contributing

Contributions are welcome to Chainlink's source code.

Please check out our contributing guidelines for more details.

Thank you!

More Repositories

1

full-blockchain-solidity-course-js

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

full-blockchain-solidity-course-py

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

hardhat-starter-kit

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

chainlink-mix

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

defi-minimal

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

documentation

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

foundry-starter-kit

Solidity
331
star
8

external-adapters-js

Monorepo containing JavaScript implementation of external adapters
TypeScript
269
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
186
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

functions-hardhat-starter-kit

JavaScript
147
star
17

chainlink-polkadot

Go
139
star
18

LinkToken

LINK Token Contracts for the Chainlink Network
Solidity
132
star
19

ccip

Cross Chain Interoperability Protocol
Go
119
star
20

huff-starter-kit

A template repo to work with huff smart contracts and learn about low level EVM opcodes. Also Horse ♘.
Solidity
101
star
21

apeworx-starter-kit

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

Web3_tutorial_Chinese

Solidity
90
star
23

chainlink-solana

Go
81
star
24

blockchain-developer-hub

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

ccip-starter-kit-foundry

This project demonstrates a couple of basic Chainlink CCIP use cases
Solidity
73
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
62
star
31

chainlink-testing-framework

A testing framework for smart contracts and Chainlink nodes
Go
61
star
32

ccip-read

TypeScript
60
star
33

ccip-cross-chain-nft

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

chainlink-starknet

Go
58
star
35

foundry-chainlink-toolkit

A plugin to use Chainlink products/services in Foundry
Solidity
57
star
36

ccip-starter-kit-hardhat

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

prediction-game

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

chainlink-local

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

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
40

ccip-defi-lending

CCIP Launch Defi Demo
JavaScript
43
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

near-protocol-contracts

Rust
26
star
46

functions-toolkit

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

chainlink-cosmos

Go
25
star
48

functions-deepdive-constellation2023

Deepdive Workshop For Constellation 2023 Hackathon
JavaScript
24
star
49

chainlink-common

SDK for building Chainlink Services and Plugins
Go
24
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
24
star
51

run-functions-dapp

Demo dApp using Chainlink Functions to bring web2 data on-chain.
TypeScript
23
star
52

wasp

Protocol-agnostic load testing library for Go
Go
23
star
53

env-enc

TypeScript
23
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

chainlink-functions-demo-app

TypeScript
18
star
57

schemas

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

paypal-adapter

TypeScript
17
star
59

ccip-owner-contracts

A set of smart contracts used for administering Chainlink contracts, most notably CCIP
Solidity
16
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

solc-api

minimal Solidity compiler service
JavaScript
14
star
66

chainlink-env

Chainlink k8s environment library
Go
14
star
67

datastreams-demo

Demo dApp using Chainlink Data Streams.
TypeScript
13
star
68

operator-ui

TypeScript
13
star
69

hello_chainlink

chainlink demos
JavaScript
12
star
70

ccip-tic-tac-toe

TypeScript
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

chainlink-automation

Go
10
star
79

chainlink-data-streams

Go
10
star
80

workshop-distributed-news

Solidity
10
star
81

solana-prediction-game

JavaScript
10
star
82

builder

A docker build file for chainlink
Dockerfile
10
star
83

chainlink-vrf

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

rwa-tokenization

TypeScript
10
star
85

cairo-starter-kit

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

hardhat-network

Deploys a basic hardhat chain for testing
Dockerfile
9
star
87

bq-example-contract

JavaScript
8
star
88

.github

TypeScript
8
star
89

ea-framework-js

TypeScript
8
star
90

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
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

timelock-worker

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

blockchain-ecosystem-map

JavaScript
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