This template provide access to Astar's modules by using astar.js
More documentation and examples on wiki
- Install dependencies
yarn
- Start the app
yarn start
- App.tsx is the entry point of the app. It has the following code for connecting to the node:
import { ApiPromise } from '@polkadot/api';
import { WsProvider } from '@polkadot/rpc-provider';
import { options } from '@astar-network/astar-api';
async function main() {
const provider = new WsProvider('ws://localhost:9944');
// OR
// const provider = new WsProvider('wss://shiden.api.onfinality.io/public-ws');
const api = new ApiPromise(options({ provider }));
await api.isReady;
// Use the api
// For example:
console.log((await api.rpc.system.properties()).toHuman());
process.exit(0);
}
main()
- Use api to interact with node
// query and display account data
const data = await api.query.system.account('5F98oWfz2r5rcRVnP9VCndg33DAAsky3iuoBSpaPUbgN9AJn');
console.log(data.toHuman())
- api
- Contains necessary options to create a polkadot.js API instance
- api-derive
- Contains utility classes and derived methods.
- types-definitions
- Polkadot.js type definitions for Astar Network.
- types
- Polkadot.js type definitions for Astar Network.
- sdk-core
- core api libraries
- precomplies
- precomplied contracts abi
yarn up @polkadot/api @polkadot/api-augment @polkadot/api-derive @polkadot/rpc-core @polkadot/types @polkadot/types-codec