A Dapp can connect Conflux Blockchain through Fluent, which is a browser extension that provides:
- A conneection 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();
Source:https://docs.confluxnetwork.org/js-conflux-sdk/docs/providers#connect-through-fluent-wallet
Comments
0 comments
Please sign in to leave a comment.