UNPKG

6.39 kBTypeScriptView Raw
1import type { RpcInterface } from '@polkadot/rpc-core/types';
2import type { Text } from '@polkadot/types';
3import type { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
4import type { Metadata } from '@polkadot/types/metadata';
5import type { CallFunction, RegistryError } from '@polkadot/types/types';
6import type { ApiDecoration, ApiInterfaceRx, ApiTypes, DecoratedErrors, DecoratedEvents, DecoratedRpc, QueryableConsts, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics } from '../types';
7import { Init } from './Init';
8export declare abstract class Getters<ApiType extends ApiTypes> extends Init<ApiType> implements ApiDecoration<ApiType> {
9 /**
10 * @description Contains the parameter types (constants) of all modules.
11 *
12 * The values are instances of the appropriate type and are accessible using `section`.`constantName`,
13 *
14 * @example
15 * <BR>
16 *
17 * ```javascript
18 * console.log(api.consts.democracy.enactmentPeriod.toString())
19 * ```
20 */
21 get consts(): QueryableConsts<ApiType>;
22 /**
23 * @description Derived results that are injected into the API, allowing for combinations of various query results.
24 *
25 * @example
26 * <BR>
27 *
28 * ```javascript
29 * api.derive.chain.bestNumber((number) => {
30 * console.log('best number', number);
31 * });
32 * ```
33 */
34 get derive(): ReturnType<Getters<ApiType>['_decorateDerive']>;
35 /**
36 * @description Errors from metadata
37 */
38 get errors(): DecoratedErrors<ApiType>;
39 /**
40 * @description Events from metadata
41 */
42 get events(): DecoratedEvents<ApiType>;
43 /**
44 * @description Returns the version of extrinsics in-use on this chain
45 */
46 get extrinsicVersion(): number;
47 /**
48 * @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.
49 */
50 get genesisHash(): Hash;
51 /**
52 * @description true is the underlying provider is connected
53 */
54 get isConnected(): boolean;
55 /**
56 * @description The library information name & version (from package.json)
57 */
58 get libraryInfo(): string;
59 /**
60 * @description Contains all the chain state modules and their subsequent methods in the API. These are attached dynamically from the runtime metadata.
61 *
62 * All calls inside the namespace, is denoted by `section`.`method` and may take an optional query parameter. As an example, `api.query.timestamp.now()` (current block timestamp) does not take parameters, while `api.query.system.account(<accountId>)` (retrieving the associated nonce & balances for an account), takes the `AccountId` as a parameter.
63 *
64 * @example
65 * <BR>
66 *
67 * ```javascript
68 * api.query.system.account(<accountId>, ([nonce, balance]) => {
69 * console.log('new free balance', balance.free, 'new nonce', nonce);
70 * });
71 * ```
72 */
73 get query(): QueryableStorage<ApiType>;
74 /**
75 * @description Allows for the querying of multiple storage entries and the combination thereof into a single result. This is a very optimal way to make multiple queries since it only makes a single connection to the node and retrieves the data over one subscription.
76 *
77 * @example
78 * <BR>
79 *
80 * ```javascript
81 * const unsub = await api.queryMulti(
82 * [
83 * // you can include the storage without any parameters
84 * api.query.balances.totalIssuance,
85 * // or you can pass parameters to the storage query
86 * [api.query.system.account, '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY']
87 * ],
88 * ([existential, [, { free }]]) => {
89 * console.log(`You have ${free.sub(existential)} more than the existential deposit`);
90 *
91 * unsub();
92 * }
93 * );
94 * ```
95 */
96 get queryMulti(): QueryableStorageMulti<ApiType>;
97 /**
98 * @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.query` and `api.tx` sections, these methods are fixed (although extensible with node upgrades) and not determined by the runtime.
99 *
100 * 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 (using known keys) and the submission of transactions.
101 *
102 * @example
103 * <BR>
104 *
105 * ```javascript
106 * api.rpc.chain.subscribeNewHeads((header) => {
107 * console.log('new header', header);
108 * });
109 * ```
110 */
111 get rpc(): DecoratedRpc<ApiType, RpcInterface>;
112 /**
113 * @description Contains the chain information for the current node.
114 */
115 get runtimeChain(): Text;
116 /**
117 * @description Yields the current attached runtime metadata. Generally this is only used to construct extrinsics & storage, but is useful for current runtime inspection.
118 */
119 get runtimeMetadata(): Metadata;
120 /**
121 * @description Contains the version information for the current runtime.
122 */
123 get runtimeVersion(): RuntimeVersion;
124 /**
125 * @description The underlying Rx API interface
126 */
127 get rx(): Pick<ApiInterfaceRx, 'tx' | 'rpc' | 'query'>;
128 /**
129 * @description The type of this API instance, either 'rxjs' or 'promise'
130 */
131 get type(): ApiTypes;
132 /**
133 * @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.
134 *
135 * @example
136 * <BR>
137 *
138 * ```javascript
139 * api.tx.balances
140 * .transfer(<recipientId>, <balance>)
141 * .signAndSend(<keyPair>, ({status}) => {
142 * console.log('tx status', status.asFinalized.toHex());
143 * });
144 * ```
145 */
146 get tx(): SubmittableExtrinsics<ApiType>;
147 /**
148 * @description Finds the definition for a specific [[CallFunction]] based on the index supplied
149 */
150 findCall(callIndex: Uint8Array | string): CallFunction;
151 /**
152 * @description Finds the definition for a specific [[RegistryError]] based on the index supplied
153 */
154 findError(errorIndex: Uint8Array | string): RegistryError;
155}