Skip to content

Latest commit

 

History

History
108 lines (84 loc) · 3.84 KB

BaseProvider.md

File metadata and controls

108 lines (84 loc) · 3.84 KB

BaseProvider

Kind: global class

new BaseProvider([options])

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

baseProvider.requestId() ⇒ string

Gen a random json rpc id. It is used in call method, overwrite it to gen your own id.

Kind: instance method of BaseProvider

baseProvider.request(data) ⇒ Promise.<*>

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]});

baseProvider.call(method, ...params) ⇒ Promise.<*>

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);

baseProvider.send(method, [params]) ⇒ Promise.<*>

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]);

baseProvider.batch(array) ⇒ Promise.<Array>

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 ]