Overview
Last updated
Was this helpful?
Last updated
Was this helpful?
The purpose of this page is to give you a sense of everything js-conflux-sdk can do and serve as a quick reference guide
Node.js environment to install this SDK
Conflux account with some CFX (Use FluentWallet to create account and get testnet CFX from )
Conflux RPC endpoint, for example https://test.confluxrpc.com
is a testnet RPC endpoint
After installing js-conflux-sdk
(via npm), you’ll need to specify the provider url. You can use the mainnet(), or testnet(), or .
With a RPC endpoint we can initialize a Conflux object, which can be used to send JSON RPC request.
Private keys are required to approve any transaction made on your behalf, conflux.wallet
provide utility help you manage your accounts
Only after you add your account to wallet, then you can use them send transactions.
Note: from Conflux-rust v1.1.1 we have import a new base32 encoded address, the hex address can not be used then.
chainId
is used to distinguish different network and prevent replay attack, currently:
mainnet: 1029
testnet: 1
Note: jsbi currently cann't pretty log, you need convert it to string before log.
In Conflux network there are there unit: CFX, Drip, Gdrip. Drip is the minimum unit in Conflux 1 CFX=10^18Drip, 1Gdrip=10^9Drip. When getting account's balance, send transaction, specify gasPrice, all unit will be Drip. The SDK has provide a class Drip, which can use to easily convert between different unit.
The SDK also provide a websocket provider, and the default Conflux node ws port is 12535
.
Use JS SDK it will be very easy to use Pub/Sub.
Quick demo of interact with contract: query balance of one CRC20 token
If you want convert a hex to number, or uint, you can use format
, for example:
The SDK also provide most common used crypto utilities in sign
Besides url
and logger
you can pass to initialize a Conflux object
There are a lot methods on cfx object which are one-to-one with . All conflux methods will return a promise, so you can use it with async/await
syntax.
Besides balance you can get a lot blockchain information through it, for example: nonce, block, transaction, receipt and so on. You can check and
From conflux-rust 1.1.1
Conflux has switch to base32Checksum address for example cfxtest:aak2rra2njvd77ezwjvx04kkds9fzagfe6d5r8e957
. It was introduced by . js-conflux-sdk
add support for it from version 1.5.10
, check for details.
Check for details
mainnet
:
testnet
:
You can find the epochNumber doc at official developer
Because in blockchain world there are a lot big numbers (uint256), only modern JS VM and Node.js support BigInt
, so we use JSBI in browser environment to handle these big number. For how to use check it's documentation
Note: When a js integer is bigger than Number.MAX_SAFE_INTEGER
(2^53 - 1 or 9,007,199,254,740,991) you should use to contain it.
Conflux node support pub/sub makes it possible to query certain items on an ongoing basis, without polling through the JSON-RPC HTTP interface, currently three topics are supported: newHeads
, epochs
, logs
, for detail explain of Pub/Sub check the
You can use this SDK get and update contract state, we have a complete for you.