README.md 4.44 KiB
Newer Older
Maciej Hirsz's avatar
Maciej Hirsz committed
# Substrate API Sidecar

REST API service intended to run next to Substrate, exposing a limited set of endpoints over HTTP
with meaningful responses.
Maciej Hirsz's avatar
Maciej Hirsz committed

### Installation

Make sure your machine has an
[up-to-date version of `rustup`](https://www.rust-lang.org/tools/install) 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:

Maciej Hirsz's avatar
Maciej Hirsz committed
```
Maciej Hirsz's avatar
Maciej Hirsz committed
yarn
Maciej Hirsz's avatar
Maciej Hirsz committed
```

### Running

```bash
# For development
yarn dev

# To build and run
Maciej Hirsz's avatar
Maciej Hirsz committed
yarn start
Maciej Hirsz's avatar
Maciej Hirsz committed
```

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

```bash
NODE_ENV=parity yarn start
```

### Fee Calculation Debugging

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

```
FEE_DEBUG=1 yarn
```

Maciej Hirsz's avatar
Maciej Hirsz committed
### Available paths

Block IDs may take two forms: a non-negative decimal integer that denotes the block _height_ **or**
a 32-byte hex string (`0x` followed by 64 hexadecimal digits) that denotes the block _hash_.

- `/block` fetch latest finalized block details.
- `/block/NUMBER` fetch block details at the block identified by 'NUMBER`.
- `/balance/ADDRESS` fetch balances for `ADDRESS` at latest finalized block.
- `/balance/ADDRESS/NUMBER` fetch balances for `ADDRESS` at the block identified by 'NUMBER`.
- `/staking/ADDRESS` fetch the staking info for `ADDRESS` at latest finalized block.
- `/staking/ADDRESS/NUMBER` fetch the staking info for `ADDRESS` at the block identified by 'NUMBER`.
- `/vesting/ADDRESS` fetch the vesting info for `ADDRESS` at latest finalized block.
- `/vesting/ADDRESS/NUMBER` fetch the vesting info for `ADDRESS` at the block identified by 'NUMBER`.
- `/metadata` fetch chain metadata at latest finalized block.
- `/metadata/NUMBER` fetch chain metadata at the block identified by 'NUMBER`.
- `/claims/ADDRESS` fetch claims data for an Ethereum `ADDRESS`.
- `/claims/ADDRESS/NUMBER` fetch claims data for an Ethereum `ADDRESS` at the block identified by 'NUMBER`.
- `/tx/artifacts/` fetch artifacts used for creating transactions at latest finalized block.
- `/tx/artifacts/NUMBER` fetch artifacts used for creating transactions at the block identified by 'NUMBER`.
joe petrowski's avatar
joe petrowski committed
- `/tx/fee-estimate` submit a transaction in order to get back a fee estimation. Expects a string
  with a hex-encoded transaction in a JSON POST body:
joe petrowski's avatar
joe petrowski committed
  curl localhost:8080/tx/fee-estimate -X POST --data '{"tx": "0x..."}' -H 'Content-Type: application/json'
  ```
  Expected result is a JSON with fee information:
  ```
  {
    "weight": "195000000",
    "class": "Normal",
    "partialFee": "165600000"
  }
  ```
- `/tx/` submit a signed transaction, expects a string with hex-encoded transaction in a JSON POST
  body:
  ```
  curl localhost:8080/tx/ -X POST --data '{"tx": "0x..."}' -H 'Content-Type: application/json'
  ```
joe petrowski's avatar
joe petrowski committed
  Expected result is a JSON with transaction hash:
Maciej Hirsz's avatar
Maciej Hirsz committed
### Configuration

Following ENV variables can be set:

- `BIND_HOST`: address on which the server will be listening, defaults to `127.0.0.1`.
- `BIND_PORT`: port on which the server will be listening, defaults to `8080`.
- `NODE_WS_URL`: WebSocket URL to which the RPC proxy will attempt to connect to, defaults to
  `ws://127.0.0.1:9944`.
- `LOG_MODE`: enable console logging of "all" HTTP requests, only "errors", or nothing by setting it to anything else. LOG_MODE defaults to only "errors".
Maciej Hirsz's avatar
Maciej Hirsz committed

If you are connecting to
[Substrate Node Template](https://github.com/substrate-developer-hub/substrate-node-template),
please add the following custom types in `config/types.json`.

```json
{
  "CUSTOM_TYPES": {
    "Address": "AccountId",
    "LookupSource": "AccountId"
  },
}

```

Maciej Hirsz's avatar
Maciej Hirsz committed
### Chain compatibility

Sidecar should be compatible with any [Substrate](https://substrate.dev/) based chain, given
constraints:
Maciej Hirsz's avatar
Maciej Hirsz committed

- The chain ought to use FRAME and the `balances` pallet.
- The chain is being finalized (by running `grandpa`).
- If the chain is running on custom Node binaries, the JSON-RPC API should be backwards compatible
  with the default Substrate Node.
Zeke Mostov's avatar
Zeke Mostov committed

### Contribute

We welcome contributions. Before submitting your PR, make sure to run the following commands:

- `yarn lint`: Make sure your code follows our linting rules. You can also run `yarn lint --fix` to automatically fix some of those errors.
- Testing coming soon!