Polka 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
- connect node: https://polkadot.js.org/api/examples/promise/01_simple_connect/ (opens in a new tab)
- get blocks: https://polkadot.js.org/api/examples/promise/02_listen_to_blocks/ (opens in a new tab)
- get balance: https://polkadot.js.org/api/examples/promise/03_listen_to_balance_change/ (opens in a new tab)
- transactions (Ordinary transactions, batch transactions, manual nonce transactions, etc.): https://polkadot.js.org/api/cookbook/tx.html (opens in a new tab)
- more: https://polkadot.js.org/api/examples/promise/ (opens in a new tab)
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 (opens in a new tab)
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 (opens in a new tab)
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": {}
}
- The node ip and port can be configured as follows: https://github.com/stafiprotocol/substrate-api-sidecar/blob/master/specs.yml (opens in a new tab)
- More: https://github.com/stafiprotocol/substrate-api-sidecar (opens in a new tab)
Api list
https://github.com/stafiprotocol/substrate-api-sidecar#available-paths (opens in a new tab)