Files
api/docs/api/classes/_base_.apibase.md
T
2018-10-12 12:52:03 +00:00

5.2 KiB

Type parameters

R

S

E

Hierarchy

ApiBase

↳ ApiPromise

↳ ApiRx

Implements

  • ApiBaseInterface<R, S, E>

Constructors

constructor

⊕ new ApiBase(wsProvider?: WsProvider): ApiBase

Defined in Base.ts:40

description: Create an instance of the class

example:

import Api from '@polkadot/api/rx';

new Api().isReady.subscribe((api) => {
  api.rpc.newHead().subscribe((header) => {
    console.log(`new block #${header.blockNumber.toNumber()}`);
  });
});

Parameters:

Param Type Description
Optional wsProvider WsProvider A WebSocket provider from rpc-provider/ws. If not specified, it will default to connecting to the localhost with the default port

Returns: ApiBase


Accessors

genesisHash

getgenesisHash(): Hash

Defined in Base.ts:71

description: Contains the genesis Hash of the attached chain. Apart from being useful to determine the actual chain, it can also be used to sign immortal transactions.

Returns: Hash


rpc

getrpc(): R

Defined in Base.ts:111

description: Contains all the raw rpc sections and their subsequent methods in the API as defined by the jsonrpc interface definitions. Unlike the dynamic api.st and api.tx sections, these methods are fixed (although extensible with node upgrades) and not determined by the runtime.

RPC endpoints available here allow for the query of chain, node and system information, in addition to providing interfaces for the raw queries of state (usine known keys) and the submission of transactions.

example:

api.rpc.chain
  .newHead()
  .subscribe((header) => {
    console.log('new header', header);
  });

Returns: R


runtimeMetadata

getruntimeMetadata(): RuntimeMetadata

Defined in Base.ts:80

description: Yields the current attached runtime metadata. Generally this is only used to construct extrinsics & storage, but is useful for current runtime inspection.

Returns: RuntimeMetadata


runtimeVersion

getruntimeVersion(): RuntimeVersion

Defined in Base.ts:89

description: Contains the version information for the current runtime.

Returns: RuntimeVersion


st

getst(): S

Defined in Base.ts:131

description: Contains all the chain state modules and their subsequent methods in the API. These are attached dynamically from the runtime metadata.

All calls inside the namespace, is denoted by section.method and may take an optional query parameter. As an example, api.st.timestamp.now() (current block timestamp) does not take parameters, while api.st.system.accountNonce(<accountId>) (retrieving the associated nonce for an account), takes the AccountId as a parameter.

example:

api.st.balances
  .freeBalance(<accountId>)
  .subscribe((balance) => {
    console.log('new balance', balance);
  });

Returns: S


tx

gettx(): E

Defined in Base.ts:153

description: Contains all the extrinsic modules and their subsequent methods in the API. It allows for the construction of transactions and the submission thereof. These are attached dynamically from the runtime metadata.

example:

api.tx.balances
  .transfer(<recipientId>, <balance>)
  .sign(<keyPair>, <accountNonce>, <blockHash (optional)>)
  .send()
  .subscribe((status) => {
    console.log('tx status', status);
  });

Returns: E


Methods

on

▸ on(type: ApiInterface$Events, handler: function): void

Defined in Base.ts:178

description: Attach an eventemitter handler to listen to a specific event

example:

* api.on('disconnected', () => {
  console.log('API has been connected to the endpoint');
});

api.on('disconnected', () => {
  console.log('API has been disconnected from the endpoint');
});

Parameters:

Param Type Description
type ApiInterface$Events The type of event to listen to. Available events are `connected`, `disconnected` and `ready`
handler function The callback to be called when the event fires. Depending on the event type, it could fire with additional arguments.

Returns: void