* Add documentation * Justification u8a decoding and json encoding (#146) * Decode Justifications * Json encoding for justifications * Bump deps * Allow extrinsic length encoding to operate on u8a[] (#148) * Fix config and move generated doc to a subfolder * Cleanup extrinsic encoding (#150) * Cleanup extrinsic encoding * Removed now-defunct type * Add uncheckedLength encoding * Add examples * Ignore package-lock since we use yarn * Cleanup examples * Add gitbook config and some base files for the doc * Do not make full doc mandatory for now * Add contributing guide, polish doc and samples * Update the deps of all samples and add yarn scripts Fix and regenerate the doc * Fix Contributing guide
13 KiB
@polkadot/api-provider
Generic transport providers to handle the transport of method calls to and from Polkadot clients from applications interacting with it. Generally, unless you are operating at a low-level and taking care of encoding and decoding of parameters/results, it won't be directly used. API interfaces building on top these providers can support various transports with the same underlying interfaces.
Usage
Installation -
npm install --save @polkadot/api-provider
Initialisation -
import WsProvider from '@polkadot/api-provider/ws';
const provider = new WsProvider('http://127.0.0.1:9944');
const version = await provider.send('client_version', []);
console.log('clientVersion', version);
Index
Classes
Interfaces
Type aliases
- HttpState
- JsonRpcObject
- JsonRpcRequest
- JsonRpcResponse
- JsonRpcResponseBase
- JsonRpcResponseBase$Error
- MockState
- MockState$Requests
- MockState$Storage
- MockState$Subscription$Callback
- MockState$Subscriptions
- ProviderInterface$Callback
- ProviderInterface$EmitCb
- ProviderInterface$Emitted
- RpcCoder
- RpcCoderState
Functions
- decodeResponse
- encodeJson
- encodeObject
- mockProvider
- mocks
- on
- rpcCoder
- send
- state
- subscribe
- unsubscribe
Type aliases
HttpState
Ƭ HttpState: object
Defined in http/types.d.ts:8
Type declaration
JsonRpcObject
Ƭ JsonRpcObject: object
Defined in types.d.ts:5
Type declaration
JsonRpcRequest
Ƭ JsonRpcRequest: * JsonRpcObject & object
*
Defined in types.d.ts:10
JsonRpcResponse
Ƭ JsonRpcResponse: * JsonRpcObject & JsonRpcResponseBase *
Defined in types.d.ts:36
JsonRpcResponseBase
Ƭ JsonRpcResponseBase: * JsonRpcResponse$Single & JsonRpcResponse$Subscription
*
Defined in types.d.ts:34
JsonRpcResponseBase$Error
Ƭ JsonRpcResponseBase$Error: object
Defined in types.d.ts:15
Type declaration
MockState
Ƭ MockState: object
Defined in mock/types.d.ts:27
Type declaration
MockState$Requests
Ƭ MockState$Requests: object
Defined in mock/types.d.ts:23
Type declaration
▸(storage: MockState$Storage, params: Array<any>): string
Parameters:
| Param | Type |
|---|---|
| storage | MockState$Storage |
| params | Array<any> |
Returns: string
MockState$Storage
Ƭ MockState$Storage: object
Defined in mock/types.d.ts:19
Type declaration
MockState$Subscription$Callback
Ƭ MockState$Subscription$Callback: function
Defined in mock/types.d.ts:8
Type declaration
▸(error: * Error | null*, value: any): void
Parameters:
| Param | Type |
|---|---|
| error | Error | null |
| value | any |
Returns: void
MockState$Subscriptions
Ƭ MockState$Subscriptions: object
Defined in mock/types.d.ts:10
Type declaration
ProviderInterface$Callback
Ƭ ProviderInterface$Callback: function
Defined in types.d.ts:38
Type declaration
▸(error: * Error | null*, result: any): void
Parameters:
| Param | Type |
|---|---|
| error | Error | null |
| result | any |
Returns: void
ProviderInterface$EmitCb
Ƭ ProviderInterface$EmitCb: function
Defined in types.d.ts:42
Type declaration
▸(value?: any): any
Parameters:
| Param | Type |
|---|---|
Optional value |
any |
Returns: any
ProviderInterface$Emitted
Ƭ ProviderInterface$Emitted: * "connected" | "disconnected" *
Defined in types.d.ts:40
RpcCoder
Ƭ RpcCoder: object
Defined in coder/json/types.d.ts:7
Type declaration
RpcCoderState
Ƭ RpcCoderState: object
Defined in coder/json/types.d.ts:14
Type declaration
Functions
decodeResponse
▸ decodeResponse(self: RpcCoderState, response: JsonRpcResponse): any
Defined in coder/json/decodeResponse.ts:22
Parameters:
| Param | Type |
|---|---|
| self | RpcCoderState |
| response | JsonRpcResponse |
Returns: any
encodeJson
▸ encodeJson(self: RpcCoderState, method: string, params: Array<any>): string
Defined in coder/json/encodeJson.ts:9
Parameters:
| Param | Type |
|---|---|
| self | RpcCoderState |
| method | string |
| params | Array<any> |
Returns: string
encodeObject
▸ encodeObject(self: RpcCoderState, method: string, params: Array<any>): JsonRpcRequest
Defined in coder/json/encodeObject.ts:8
Parameters:
| Param | Type |
|---|---|
| self | RpcCoderState |
| method | string |
| params | Array<any> |
Returns: JsonRpcRequest
mockProvider
▸ mockProvider(): ProviderInterface
Defined in mock/index.ts:18
A moock provider mainly used for testing.
Returns: ProviderInterface The mock provider
mocks
▸ mocks(__namedParameters: object): void
Defined in mock/mocks.ts:68
Parameters:
| Param | Type |
|---|---|
| __namedParameters | object |
Returns: void
on
▸ on(self: MockState, type: ProviderInterface$Emitted, sub: ProviderInterface$EmitCb): void
Defined in mock/on.ts:8
Parameters:
| Param | Type |
|---|---|
| self | MockState |
| type | ProviderInterface$Emitted |
| sub | ProviderInterface$EmitCb |
Returns: void
rpcCoder
▸ rpcCoder(): RpcCoder
Defined in coder/json/index.ts:12
Returns: RpcCoder
send
▸ send(__namedParameters: object, method: string, params: Array<any>): Promise<any>
Defined in mock/send.ts:7
Parameters:
| Param | Type |
|---|---|
| __namedParameters | object |
| method | string |
| params | Array<any> |
Returns: Promise<any>
state
▸ state(): MockState
Defined in mock/state.ts:38
Returns: MockState
subscribe
▸ subscribe(self: MockState, type: string, method: string, params: Array<any>): Promise<number>
Defined in mock/subscribe.ts:7
Parameters:
| Param | Type |
|---|---|
| self | MockState |
| type | string |
| method | string |
| params | Array<any> |
Returns: Promise<number>
unsubscribe
▸ unsubscribe(self: MockState, type: string, name: string, id: number): Promise<boolean>
Defined in mock/unsubscribe.ts:7
Parameters:
| Param | Type |
|---|---|
| self | MockState |
| type | string |
| name | string |
| id | number |
Returns: Promise<boolean>