• Stars
    star
    245
  • Rank 165,304 (Top 4 %)
  • Language
    TypeScript
  • License
    GNU General Publi...
  • Created almost 5 years ago
  • Updated 2 months ago

Reviews

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

Repository Details

REST service that makes it easy to interact with blockchain nodes built using Substrate's FRAME framework.



@substrate/api-sidecar

REST service that makes it easy to interact with blockchain nodes built using Substrate's FRAME framework.

npm Github Actions GPL-3.0-or-later



Note

v1.0.0 was released on 2020-10-23. This major release introduced several renamed endpoints as breaking changes. It is important that users complete the transition to the new endpoints ASAP so they are ready for any subsequent emergency updates. Please visit the MIGRATION_GUIDE to learn more.

Prerequisites

<= v15.0.0

This service requires Node versions 14 or higher.

Compatibility:

Node Version Stablility
v14.x.x Stable
v16.x.x Stable
v17.x.x Stable
v18.x.x Stable
v19.x.x Pending

>= v16.0.0

This service requires Node versions 18.14 or higher.

Compatibility:

Node Version Stablility
v18.14.x Stable
v19.x.x Pending

NOTE: Node LTS (long term support) versions start with an even number, and odd number versions are subject to a 6 month testing period with active support before they are unsupported. It is recommended to use sidecar with a stable actively maintained version of node.js.

Table of contents

NPM package installation and usage

Global installation

Install the service globally:

npm install -g @substrate/api-sidecar
# OR
yarn global add @substrate/api-sidecar

Run the service from any directory on your machine:

substrate-api-sidecar

To check your version you may append the --version flag to substrate-api-sidecar.

Local installation

Install the service locally:

npm install @substrate/api-sidecar
# OR
yarn add @substrate/api-sidecar

Run the service from within the local directory:

node_modules/.bin/substrate-api-sidecar

Finishing up

Jump to the configuration section for more details on connecting to a node.

Click here for full endpoint docs.

In the full endpoints doc, you will also find the following trace related endpoints :

  • /experimental/blocks/{blockId}/traces/operations?actions=false
  • /experimental/blocks/head/traces/operations?actions=false
  • /experimental/blocks/{blockId}/traces
  • /experimental/blocks/head/traces

To have access to these endpoints you need to :

  1. Run your node with the flag β€”unsafe-rpc-external
  2. Check in sidecar if BlocksTrace controller is active for the chain you are running.

Currently BlocksTrace controller is active in Polkadot and Kusama.

Source code installation and usage

Quick install

Simply run yarn.

Rust development installation

If you are looking to hack on the calc Rust crate make sure your machine has an up-to-date version of rustup installed to manage Rust dependencies.

Install wasm-pack if your machine does not already have it:

cargo install wasm-pack

Use yarn to do the remaining setup:

yarn

Running

# For live reload in development
yarn dev

# To build and run
yarn build
yarn start

Jump to the configuration section for more details on connecting to a node.

Configuration

To use a specific env profile (here for instance a profile called 'env.sample'):

NODE_ENV=sample yarn start

For more information on our configuration manager visit its readme here. See Specs.ts to view the env configuration spec.

Express server

  • SAS_EXPRESS_BIND_HOST: address on which the server will be listening, defaults to 127.0.0.1.
  • SAS_EXPRESS_PORT: port on which the server will be listening, defaults to 8080.
  • SAS_EXPRESS_KEEP_ALIVE_TIMEOUT: Set the keepAliveTimeout in express.

Substrate node

  • SAS_SUBSTRATE_URL: URL to which the RPC proxy will attempt to connect to, defaults to ws://127.0.0.1:9944. Accepts both a websocket, and http URL.

Custom substrate types

Some chains require custom type definitions in order for Sidecar to know how to decode the data retrieved from the node. Sidecar affords environment variables which allow the user to specify an absolute path to a JSON file that contains type definitions in the corresponding formats. Consult polkadot-js/api for more info on the type formats (see RegisteredTypes). There is a helper CLI tool called generate-type-bundle that can generate a typesBundle.json file for you using chain information from @polkadot/apps-config. The generated json file from this tool will work directly with the SAS_SUBSTRATE_TYPES_BUNDLE ENV variable.

  • SAS_SUBSTRATE_TYPES_BUNDLE: a bundle of types with versioning info, type aliases, derives, and rpc definitions. Format: OverrideBundleType (see typesBundle).
  • SAS_SUBSTRATE_TYPES_CHAIN: type definitions keyed by chainName. Format: Record<string, RegistryTypes> (see typesChain).
  • SAS_SUBSTRATE_TYPES_SPEC: type definitions keyed by specName. Format: Record<string, RegistryTypes> (see typesSpec).
  • SAS_SUBSTRATE_TYPES: type definitions and overrides, not keyed. Format: RegistryTypes (see types).

You can read more about defining types for polkadot-js here.

Connecting a modified node template

Polkadot-js can recognize the standard node template and inject the correct types, but if you have modified the name of your chain in the node template you will need to add the types manually in a JSON types file like so:

// my-chains-types.json
{
  "Address": "AccountId",
  "LookupSource": "AccountId"
}

and then set the enviroment variable to point to your definitions:

export SAS_SUBSTRATE_TYPES=/path/to/my-chains-types.json

Logging

  • SAS_LOG_LEVEL: The lowest priority log level to surface, defaults to info. Tip: set to http to see all HTTP requests.
  • SAS_LOG_JSON:Whether or not to have logs formatted as JSON, defaults to false. Useful when using stdout to programmatically process Sidecar log data.
  • SAS_LOG_FILTER_RPC: Whether or not to filter polkadot-js API-WS RPC logging, defaults to false.
  • SAS_LOG_STRIP_ANSI: Whether or not to strip ANSI characters from logs, defaults to false. Useful when logging RPC calls with JSON written to transports.
  • SAS_LOG_WRITE: Whether or not to write logs to a log file. Default is set to false. Accepts a boolean value. The log files will be written as logs.log. NOTE: It will only log what is available depending on what SAS_LOG_LEVEL is set to.
  • SAS_LOG_WRITE_PATH: Specifies the path to write the log files. Default will be where the package is installed.
  • SAS_LOG_WRITE_MAX_FILE_SIZE: Specifies in bytes what the max file size for the written log files should be. Default is 5242880 (5MB). NOTE Once the the max amount of files have reached their max size, the logger will start to rewrite over the first log file.
  • SAS_LOG_WRITE_MAX_FILES: Specifies how many files can be written. Default is 5.

Log levels

Log levels in order of decreasing importance are: error, warn, info, http, verbose, debug, silly.

http status code range log level
code < 400 http
400 <= code < 500 warn
500 < code error

RPC logging

If looking to track raw RPC requests/responses, one can use yarn start:log-rpc to turn on polkadot-js's logging. It is recommended to also set SAS_LOG_STRIP_ANSI=true to increase the readability of the logging stream.

N.B. If running yarn start:log-rpc, the NODE_ENV will be set to test. In order still run your .env file you can symlink it with .env.test. For example you could run ln -s .env.myEnv .env.test && yarn start:log-rpc to use .env.myEnv to set ENV variables. (see linux commands ln and unlink for more info.)

Prometheus server

Prometheus metrics can be enabled by running sidecar with the following flag :

yarn start --prometheus

You can also define a custom port by running :

yarn start --prometheus --prometheus-port=<YOUR_CUSTOM_PORT>

The metrics endpoint can then be accessed :

  • on the default port : http://127.0.0.1:9100/metrics or
  • on your custom port if you defined one : http://127.0.0.1:<YOUR_CUSTOM_PORT>/metrics

That way you will have access to the default prometheus metrics and one extra custom metric called sas_http_errors (of type counter). This counter is increased by 1 every time an http error has occured in sidecar.

Debugging fee and staking payout calculations

It is possible to get more information about the fee and staking payout calculation process logged to the console. Because these calculations happens in the statically compiled web assembly part, a re-compile with the proper environment variable set is necessary:

CALC_DEBUG=1 sh calc/build.sh

Available endpoints

Click here for full endpoint docs.

Chain integration guide

Click here for chain integration guide.

Docker

With each release, the maintainers publish a docker image to dockerhub at parity/substrate-api-sidecar

Pull the latest release

docker pull docker.io/parity/substrate-api-sidecar:latest

The specific image tag matches the release version.

Or build from source

yarn build:docker

Run

# For default use run:
docker run --rm -it --read-only -p 8080:8080 substrate-api-sidecar

# Or if you want to use environment variables set in `.env.docker`, run:
docker run --rm -it --read-only --env-file .env.docker -p 8080:8080 substrate-api-sidecar

NOTE: While you could omit the --read-only flag, it is strongly recommended for containers used in production.

then you can test with:

curl -s http://0.0.0.0:8080/blocks/head | jq

N.B. The docker flow presented here is just a sample to help get started. Modifications may be necessary for secure usage.

Contribute

Need help or want to contribute ideas or code? Head over to our CONTRIBUTING doc for more information.

Notes for maintainers

Commits

All the commits in this repo follow the Conventional Commits spec. When merging a PR, make sure 1) to use squash merge and 2) that the title of the PR follows the Conventional Commits spec.

Updating polkadot-js dependencies

  1. Every Monday the polkadot-js ecosystem will usually come out with a new release. It's important that we keep up, and read the release notes for any breaking changes or high priority updates. In order to update all the dependencies and resolutions run yarn up "@polkadot/*".

  2. Ensure everything is up to date and working by running the following:

    yarn
    yarn dedupe
    yarn build
    yarn lint
    yarn test
    yarn test:historical-e2e-tests
    yarn test:latest-e2e-tests
    
  3. Commit the dependency updates with a name like fix(deps): update pjs api (title depending on what got updated, see commit history for other examples of this), and wait to get it merged.

  4. Follow RELEASE.md next if you're working through a full sidecar release. This will involve creating a separate PR where the changelog and versions are bumped.

Hardware requirements

Disk Space

Sidecar is a stateless program and thus should not use any disk space.

Memory

The requirements follow the default of node.js processes which is an upper bound in HEAP memory of a little less than 2GB thus 4GB of memory should be sufficient.

Running sidecar and a node

Please note that if you run sidecar next to a substrate node in a single machine then your system specifications should improve significantly.

  • Our official specifications related to validator nodes can be found in the polkadot wiki page.
  • Regarding archive nodes :
    • again as mentioned in the polkadot wiki page, the space needed from an archive node depends on which block we are currently on (of the specific chain we are referring to).
    • there are no other hardware requirements for an archive node since it is not time critical (archive nodes do not participate in the consensus).

Benchmarks

During the benchmarks we performed, we concluded that sidecar would use a max of 1.1GB of RSS memory.

The benchmarks were:

  • using 4 threads over 12 open http connections and
  • were overloading the cache with every runtime possible on polkadot.

Hardware specs in which the benchmarks were performed:

Machine type:
n2-standard-4 (4 vCPUs, 16 GB memory)

CPU Platform:
Intel Cascade Lake

Hard-Disk:
500GB

More Repositories

1

substrate

Substrate: The platform for blockchain innovators
Rust
8,212
star
2

polkadot

Polkadot Node Implementation
Rust
6,865
star
3

ink

Parity's ink! to write smart contracts.
Rust
1,316
star
4

wasmi

WebAssembly (Wasm) interpreter.
Rust
1,269
star
5

polkadot-sdk

The Parity Polkadot Blockchain SDK
Rust
979
star
6

jsonrpc

Rust JSON-RPC implementation
Rust
752
star
7

parity-bitcoin

The Parity Bitcoin client
Rust
726
star
8

cumulus

Write Parachains on Substrate
Rust
618
star
9

parity-signer

Air-gapped crypto wallet.
Rust
539
star
10

frontier

Ethereum compatibility layer for Substrate.
Rust
496
star
11

polkadot-launch

Simple CLI tool to launch a local Polkadot test network
TypeScript
458
star
12

jsonrpsee

Rust JSON-RPC library on top of async/await
Rust
457
star
13

parity-wasm

WebAssembly serialization/deserialization in rust
Rust
395
star
14

subxt

Submit extrinsics (transactions) to a substrate node via RPC
Rust
317
star
15

parity-bridge

Rust
317
star
16

substrate-telemetry

Polkadot Telemetry service
Rust
303
star
17

smoldot

Alternative client for Substrate-based chains.
Rust
286
star
18

parity-common

Collection of crates used in Parity projects
Rust
284
star
19

parity-bridges-common

Collection of Useful Bridge Building Tools πŸ—οΈ
Rust
265
star
20

parity-db

Experimental blockchain database
Rust
263
star
21

banana_split

Shamir's Secret Sharing for people with friends
TypeScript
259
star
22

parity-scale-codec

Lightweight, efficient, binary serialization and deserialization codec
Rust
244
star
23

substrate-connect

Run Wasm Light Clients of any Substrate based chain directly in your browser.
TypeScript
230
star
24

cargo-contract

Setup and deployment tool for developing Wasm based smart contracts via ink!
Rust
226
star
25

trie

Base-16 Modified Patricia Merkle Tree (aka Trie)
Rust
201
star
26

substrate-archive

Blockchain Indexing Engine
Rust
197
star
27

shasper

Parity Shasper beacon chain implementation using the Substrate framework.
Rust
196
star
28

parity-zcash

Rust implementation of Zcash protocol
Rust
184
star
29

cachepot

cachepot is `sccache` with extra sec, which in turn is `ccache` with cloud storage
Rust
174
star
30

libsecp256k1

Pure Rust Implementation of secp256k1.
Rust
172
star
31

homebrew-paritytech

Homebrew tap for ethcore
Ruby
160
star
32

zombienet

A cli tool to easily spawn ephemeral Polkadot/Substrate networks and perform tests against them.
TypeScript
158
star
33

polkadot-staking-dashboard

A dashboard for Polkadot staking and nomination pools.
TypeScript
152
star
34

xcm-format

Polkadot Cross Consensus-system Message format.
143
star
35

finality-grandpa

finality gadget for blockchains using common prefix agreement
Rust
139
star
36

substrate-contracts-node

Minimal Substrate node configured for smart contracts via pallet-contracts.
Rust
124
star
37

capi

[WIP] A framework for crafting interactions with Substrate chains
TypeScript
105
star
38

grandpa-bridge-gadget

A Bridge Gadget to Grandpa Finality.
Rust
99
star
39

substrate-debug-kit

A collection of debug tools, scripts and libraries on top of substrate.
Rust
94
star
40

ink-examples

A set of examples for ink! smart contract language. Happy hacking!
Rust
89
star
41

subport

Parity Substrate(-based) chains usage and development support
Rust
84
star
42

wasm-utils

Rust
82
star
43

trappist

Rust
82
star
44

txwrapper-core

Tools for FRAME chain builders to publish chain specific offline transaction generation libraries.
TypeScript
77
star
45

substrate-playground

Start hacking your substrate runtime in a web based VSCode like IDE
TypeScript
74
star
46

scale-info

Info about SCALE encodable Rust types
Rust
73
star
47

parity-tokio-ipc

Parity tokio-ipc
Rust
73
star
48

substrate-light-ui

Minimal, WASM-light-client-bundled Substrate wallet for balance transfers
TypeScript
72
star
49

substrate-ui

Bondy Polkadot UI
JavaScript
72
star
50

statemint

Statemint Node Implementation
Rust
71
star
51

canvas

Node implementation for Canvas β€’ a Substrate parachain for smart contracts.
Rust
69
star
52

substrate-up

Scripts for working with new Substrate projects
Shell
66
star
53

useink

A React hooks library for ink!
TypeScript
62
star
54

stateless-blockchain

Stateless Blockchain on Substrate using RSA Accumulators
Rust
60
star
55

txwrapper

Helper funtions for offline transaction generation.
TypeScript
58
star
56

contracts-ui

Web application for deploying wasm smart contracts on Substrate chains that include the FRAME contracts pallet
TypeScript
58
star
57

awesome-ink

A curated list of awesome projects related to Parity's ink!.
56
star
58

srtool

A fork of chevdor's srtool
Shell
56
star
59

cargo-unleash

cargo release automatisation tooling for massiv mono-repos
Rust
55
star
60

ss58-registry

Registry for SS58 account types
Rust
55
star
61

oo7

The Bonds framework along with associated modules.
JavaScript
53
star
62

diener

Diener - dependency diener is a tool for easily changing https://github.com/paritytech/substrate or https://github.com/paritytech/polkadot dependency versions
Rust
52
star
63

lunarity

Lunarity - a Solidity parser in Rust
Rust
50
star
64

nohash-hasher

An implementation of `std :: hash :: Hasher` which does not hash at all.
Rust
49
star
65

arkworks-extensions

Library to integrate arkworks-rs/algebra into Substrate
Rust
47
star
66

wasm-instrument

Instrument and transform wasm modules.
Rust
47
star
67

asset-transfer-api

Typescript API aiming to provide clear, and simple to use tools for transferring assets across common good parachains.
TypeScript
43
star
68

fleetwood

Testbed repo for trying out ideas of what a smart contract API in Rust would look like
Rust
41
star
69

scripts

Collection of Dockerfiles, scripts and related resources
Dockerfile
40
star
70

trappist-extra

Dart
38
star
71

polkadot-introspector

A collection of tools focused on debugging and monitoring the relay chain and parachain progress from a 🐦-view
Rust
38
star
72

parity-extension

Parity Chrome Extension
JavaScript
37
star
73

rhododendron

Asynchronously safe BFT consensus, implementation in Rust
Rust
36
star
74

desub

Decode Substrate with Backwards-Compatible Metadata
Rust
36
star
75

ethkey

Ethereum key generator
Rust
35
star
76

psvm

Polkadot SDK Version Manager
Rust
35
star
77

substrate-open-working-groups

The Susbstrate Open Working Groups (SOWG) are community-based mechanisms to develop standards, specifications, implementations, guidelines or general initiatives in regards to the Substrate framework. It could, but not restricted to, lead to new Polkadot Standards Proposals. SOWG is meant as a place to find and track ongoing efforts and enable everybody with similar interests to join and contribute.
35
star
78

substrate-bip39

Rust
34
star
79

primitives

Rust
34
star
80

parity-config-generator

Parity Config Generator
JavaScript
34
star
81

zombienet-sdk

ZombieNet SDK
Rust
33
star
82

Nomidot

Staking Portal for Polkadot and Kusama
TypeScript
32
star
83

subdb

Experimental domain-specific database for Substrate
Rust
32
star
84

polkadot-api

TypeScript
31
star
85

polkadot-testnet-faucet

TypeScript
30
star
86

polkassembly

Polkassembly now has a new home:
TypeScript
30
star
87

pallet-contracts-waterfall

Collection of simple Substrate smart contract examples written in Rust, AssemblyScript, Solang and the smart contract language ink! to test substrates pallet-contracts module
TypeScript
30
star
88

metadata-portal

Metadata portal for Parity Signer
TypeScript
29
star
89

polkadot-onboard

A wallet integration SDK to facilitate adding different type of wallets (extension, WC, Ledger) to Dapps.
TypeScript
28
star
90

vscode-substrate

Substrate Marketplace VSCode Plugin
TypeScript
28
star
91

oo7-bare

The Bond API.
JavaScript
27
star
92

bigint

Rust
27
star
93

extended-parachain-template

Node template to build parachains with all the required pallets. Slightly opinionated based on what majority of parachain teams are using.
Rust
27
star
94

orchestra

A partial actor pattern with a global orchestrator.
Rust
27
star
95

polkadot-scripts

Collection of random scripts and utilities written for Polkadot
TypeScript
27
star
96

sub-flood

Flooding substrate node with transactions
TypeScript
26
star
97

polkadot-cloud

[BETA] A library and automated platform for developing and publishing assets for Polkadot dapps.
TypeScript
25
star
98

ink-playground

Browser Based Playground for editing, sharing & compiling ink! Smart Contracts
Rust
25
star
99

link

Unstoppable URL shortener built with the ink! smart contract language.
TypeScript
25
star
100

sms-verification

SMS verification for Parity.
JavaScript
25
star