Javascript Custom RPC
Frequency Custom RPC and Types for Polkadot JS API
An easy way to get all the custom rpc and types config to be able to easily use Frequency with the Polkadot JS API library.
Getting Started
npm install @dsnp/frequency-api-augment
(API Augmentation Library)npm install @polkadot/api
(Polkadot API Library)
Usage
For details on use, see the Polkadot API library documentation.
import { options } from "@dsnp/frequency-api-augment";
import { ApiPromise } from '@polkadot/api';
const api = await ApiPromise.create({
...options,
});
const { options } = require("@dsnp/frequency-api-augment");
const { ApiPromise } = require('@polkadot/api');
const api = await ApiPromise.create({
...options,
});
Contributing
See CONTRIBUTING.md for more information.
Updating Definitions
- Update
./definitions
- Build and start the chain (does not need to be on-boarded)
- Run
npm run fetch:local
- Commit changes
Helpful Notes
Option
Optional responses are not mapped to null
and instead return an object with a few properties.
For more details see the code for the Option class.
const optionalExample = await api.rpc.msa.getMsaId(account);
if (!optionalExample.isEmpty) {
return optionalExample.value;
}
return null;
Vec
Vector responses are not mapped directly to a JavaScript Array.
Instead they are mapped to the Vec class which does extend Array.
Thus, you can still use map
, forEach
, etc... with responses or access the values directing via .values()
.
License
Distributed under the Apache 2.0 License. See LICENSE
for more information.