UNPKG

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