Stake GuideStaFi ChainPolka JS Library

To facilitate the access of wallets, browsers and other tools, StaFi chose Substrate. We have also sorted mature js api database, such as polkadot-js/api, which can interact with StaFi through wss, or txwrapper, which can build transaction data through api to support offline transactions. Meanwhile, sidecar can interact with StaFi through http rpc api. The details are as follows:

polkadot-js/api (Document)

The API provides application developers the ability to query a node and interact with the Polkadot or Substrate chains using Javascript. Here you will find documentation and examples to get you started.

Dependent on

  • npm
  • StaFi full node (Run a node)

Install

yarn add @polkadot/api

Examples

txwrapper api (github)

Helper functions for offline transaction generation.

Dependent on

  • npm
  • StaFi full node (Run a node)

Install

yarn add @substrate/txwrapper

De/Encrypt, Send Transaction Cases:

https://github.com/paritytech/txwrapper/tree/master/examples

Note:

  • When developing StaFi App,you can use substrateMaster.ts
  • You can modify the node ip and port in util.ts.

API List

https://github.com/paritytech/txwrapper/tree/master/docs/globals.md

Sidecar json api (github)

REST API service intended to run next to Substrate, exposing a limited set of endpoints over HTTP with meaningful responses.

Dependent on

  • npm
  • cargo
  • StaFi full node (Run a node)

Install

  • Install cargo if your machine does not already have it:
curl https://sh.rustup.rs -sSf | sh
  • 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
cargo install wasm-pack
#When you developing Stafi App,config/types.json can modified as follows:
{
   "CUSTOM_TYPES": {}
}

Api list

https://github.com/stafiprotocol/substrate-api-sidecar#available-paths