0.0.0-062dac • Published 2 years ago

@dsnp/mrc-rpc v0.0.0-062dac

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Javascript Custom RPC

Contributors Forks Stargazers Issues MIT License

MRC 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 MRC with the Polkadot JS API library.

Getting Started

  • npm install @polkadot/api (Polkadot API Library)
  • npm install @dsnp/mrc-rpc

Usage

For details on use, see the Polkadot API library documentation.

// es6 style imports
import { ApiPromise } from '@polkadot/api';
import { rpc, types } from "@dsnp/mrc-rpc";
// ...

const mrcAPI = await ApiPromise.create({
    // ...
    rpc,
    types,
});
// commonjs require
const { ApiPromise } = require('@polkadot/api');
const { rpc, types } = require("@dsnp/mrc-rpc");
// ...

const mrcAPI = await ApiPromise.create({
    // ...
    rpc,
    types,
});

Contributing

See CONTRIBUTING.md for more information.

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);
// Does the Option have a value?
if (!optionalExample.isEmpty) {
    // Get the value
    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.