diff --git a/packages/api/README.md b/packages/api/README.md index d6929dd0a1..3e2e1b7edd 100644 --- a/packages/api/README.md +++ b/packages/api/README.md @@ -4,8 +4,8 @@ The Polkadot-JS API provides easy-to-use wrappers around JSONRPC calls that flow The API wrappers provide a standard interface for use - -- A static `.create()` that returns an API instance when connected, decorated and ready-to use -- The above is just a wrapper for `new Api() `, exposing the `isReady` getter +- A static `.create()` that returns an API instance when connected, decorated and ready-to use. ApiOptions can include an optional WsProvider and optional custom type definitions `{ provider: , types: }`. +- The above is just a wrapper for `new Api() `, exposing the `isReady` getter - `api.rpc.
.` provides access to actual RPC calls, be it for queries, submission or retrieving chain information - [RPC (node interface)](../METHODS_RPC.md) - `api.query.
.` provides access to chain state queries. These are dynamically populated based on what the runtime provides @@ -62,6 +62,29 @@ api.rpc.chain.subscribeNewHead().subscribe((header) => { }); ``` +## Registering custom types + +Additional types used by runtime modules can be added when a new instance of the API is created. This is necessary if the runtime modules use types which are not available in the base Substrate runtime. + +```javascript +import { ApiPromise } from '@polkadot/api'; + +// initialise via static create and register custom types +const api = await ApiPromise.create({ + types: { + CustomTypesExample: { + "id": "u32", + "data": "Vec", + "deposit": "Balance", + "owner": "AccountId", + "application_expiry": "Moment", + "whitelisted": "bool", + "challenge_id": "u32" + } + } +}); +``` + ## Users Some of the users of the API (let us know if you are missing from the list), include -