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
  • Choosing How to Connect to Your Node
  • Connect through Fluent Wallet

Was this helpful?

Edit on GitHub
  1. Guides

Providers

PreviousGuidesNextHow to Connect Fluent

Last updated 1 year ago

Was this helpful?

The provider is how blockchain SDK talks to the blockchain. Providers take JSON-RPC requests and return the response. This is normally done by submitting the request to an HTTP or Websocket based server.

Choosing How to Connect to Your Node

Most nodes have a variety of ways to connect to them. The most common ways to connect to your node are:

  • Websockets (works remotely, faster than HTTP)

  • HTTP (more nodes support it)

Currently, js-conflux-sdk has support for both HTTP and Websockets. Normally, websockets is recommended than HTTP, because it's faster and can use . If you want to use the PubSub API, websocket provider is the only choice. Conflux-rust's HTTP default port is 12537, websocket default port is 12535. They can be changed through .

When initialize a Conflux object, the underline provider can be configured through the url option. If you want to use HTTP provider, then provide an HTTP URL:

const cfxClient = new Conflux({
  url: 'https://test.confluxrpc.com',
  networkId: 1,
});

If want use websockts provider then provide a WSS URL.

const cfxClient = new Conflux({
  url: 'wss://test.confluxrpc.com',
  networkId: 1,
});

Connect through Fluent Wallet

  • A connection to the Conflux network (a Provider)

  • Holds your private key and helps you sign things (a Signer)

js-conflux-sdk (v2) can work with Fluent to talk with Conflux blockchain, simply by set conflux to the Conflux instance's provider.

Note: Fluent wallet won't export window.confluxJS anymore, Dapp developers need to install js-conflux-sdk by themselves and set Conflux instance's provider to Fluent provider.

// Firstly initialize the Conflux object without url
// Here Conflux indicate the SDK, TreeGraph.Conflux is the class used to talk with blockchain
const cfxClient = new TreeGraph.Conflux({
  networkId: 1,
});
// "conflux" indicate the fluent's browser object
cfxClient.provider = conflux;
// update sdk network id when chain changed
conflux.on('chainChanged', cfxClient.updateNetworkId);

If you can't determine the networkId of the selected network of Fluent, you can get it asynchronously like below.

const cfxClient = new TreeGraph.Conflux();
cfxClient.provider = conflux;
conflux.on('chainChanged', cfxClient.updateNetworkId);
await cfxClient.updateNetworkId();

A Dapp can connect Conflux Blockchain through , which is a browser extension that provides:

Pub/Sub methods
config file
Fluent