js-conflux-sdk
Conflux Doc
  • Home
  • Introduction
  • QuickStart
  • Overview
  • Contrast with web3.js
  • Guides
    • Providers
    • How to Connect Fluent
    • CIP37 Address
    • Account
    • Sending Transaction
    • Interact with Contract
    • Sign methods
    • Error Handling
    • Batch RPC
  • API
    • Conflux
    • PoS
    • TxPool
    • Provider
    • Drip
    • Transaction
    • Wallet
  • Release notes
  • v2.0 Changes
  • FAQs
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. API

Provider

PreviousTxPoolNextDrip

Last updated 2 years ago

Was this helpful?

BaseProvider

Kind: global class

    • ⇒ string

    • ⇒ Promise.<*>

    • ⇒ Promise.<*>

    • ⇒ Promise.<*>

    • ⇒ Promise.<Array>

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.

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

Call a json rpc method with params

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

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

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

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 ]

Kind: instance method of

Kind: instance method of Returns: Promise.<*> - Json rpc method return value.

Kind: instance method of Returns: Promise.<*> - Json rpc method return value.

Kind: instance method of Returns: Promise.<*> - Json rpc method return value.

Kind: instance method of

BaseProvider
new BaseProvider([options])
.requestId()
.request(data)
.call(method, ...params)
.send(method, [params])
.batch(array)
BaseProvider
BaseProvider
BaseProvider
BaseProvider
BaseProvider