Kind: global class
- BaseProvider
- new BaseProvider([options])
- .requestId() ⇒
string
- .request(data) ⇒
Promise.<*>
- .call(method, ...params) ⇒
Promise.<*>
- .send(method, [params]) ⇒
Promise.<*>
- .batch(array) ⇒
Promise.<Array>
Param | Type | Default | Description |
---|---|---|---|
[options] | object |
||
options.url | string |
Full json rpc http url | |
[options.timeout] | number |
30*1000 |
Request time out in ms |
[options.retry] | number |
1 |
Retry number |
[options.keepAlive] | boolean |
false |
Whether open the http keep-alive option |
[options.logger] | object |
Logger with info and error |
Gen a random json rpc id.
It is used in call
method, overwrite it to gen your own id.
Kind: instance method of BaseProvider
Call a json rpc method with params
Kind: instance method of BaseProvider
Returns: Promise.<*>
- Json rpc method return value.
Param | Type | Description |
---|---|---|
data | object |
|
data.method | string |
Json rpc method name. |
[data.params] | array |
Json rpc method params. |
Example
> await provider.request({method: 'cfx_epochNumber'});
> await provider.request({method: 'cfx_getBlockByHash', params: [blockHash]});
Call a json rpc method with params
Kind: instance method of BaseProvider
Returns: Promise.<*>
- Json rpc method return value.
Param | Type | Description |
---|---|---|
method | string |
Json rpc method name. |
...params | Array.<any> |
Json rpc method params. |
Example
> await provider.call('cfx_epochNumber');
> await provider.call('cfx_getBlockByHash', blockHash);
Send a json rpc method request
Kind: instance method of BaseProvider
Returns: Promise.<*>
- Json rpc method return value.
Param | Type | Description |
---|---|---|
method | string |
Json rpc method name. |
[params] | array |
Json rpc method params. |
Example
> await provider.send('cfx_epochNumber');
> await provider.send('cfx_getBlockByHash', [blockHash]);
Batch call json rpc methods with params
Kind: instance method of BaseProvider
Param | Type | Description |
---|---|---|
array | Array.<object> |
Array of object with "method" and "params" |
Example
> await provider.batch([
{ method: 'cfx_epochNumber' },
{ method: 'cfx_getBalance', params: ['cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp'] },
{ method: 'InValidInput' },
])
[ '0x3b734d', '0x22374d959c622f74728', RPCError: Method not found ]