v2.0 Changes
js-conflux-sdk v2.0 has imported several big features.

Group RPC methods by namespace

From Conflux-rust v2.0.0, the pos RPC group has been added, which can be used to get PoS chain info. js-conflux-sdk will add support to PoS related RPC in v2.0. These methods are located at Conflux's sub object pos conflux.pos, for example:
1
async function main() {
2
const conflux = new Conflux({
3
url: 'https://test.confluxrpc.com',
4
networkId: 1
5
});
6
const status = await conflux.pos.getStatus();
7
console.log('Current PoS status: ', status);
8
/*
9
{
10
epoch: 29,
11
latestCommitted: 1725,
12
latestTxNumber: '0x1e36',
13
latestVoted: 1728,
14
pivotDecision: {
15
blockHash: '0xc8c2c58ef952f48adf00d6204d6e930f23aee26c6b9a903820bea1c012f72f3e',
16
height: 120480
17
}
18
}
19
*/
20
}
Copied!
Check PoS RPC documentation for the complete method list.
And previous cfx RPC methods are also been moved to their own namespace, for example:
1
const balance = await conflux.cfx.getBalance('cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp');
Copied!
Besides txpool and trace namespace is also added, so js-sdk v2.0 have four RPC namespace:
  • cfx
  • pos
  • txpool
  • trace
There also is an advanced namespace, which will provide some useful combined RPC utilities, for example:
  • getNextUsableNonce
  • getPoSInterestRate

Add new Internal contracts

Two more internal contracts are added:
  • ConfluxContext
  • PoSRegister

Add support for batch request RPC

v2.0 has add support for RPC batch invoke, for example:
1
const batcher = conflux.BatchRequest();
2
batcher.add(conflux.cfx.getStatus.request());
3
batcher.add(conflux.cfx.getBalance.request('cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp'));
4
5
const [status, balance] = await batcher.execute();
Copied!
Check here for detail introduction.

Browser exported SDK name changed to TreeGraph

Note this is a breaking change
From v2.0 the browser exported SDK class name has change from Conflux to TreeGraph.
Previous
1
<script type="text/javascript">
2
const conflux = new window.Conflux.Conflux({
3
url: 'https://test.confluxrpc.com',
4
logger: console,
5
networkId: 1,
6
});
7
</script>
Copied!
Currently:
1
<script type="text/javascript">
2
const conflux = new window.TreeGraph.Conflux({
3
url: 'https://test.confluxrpc.com',
4
logger: console,
5
networkId: 1,
6
});
7
</script>
Copied!

Enable fast send transaction

If your RPC endpoint support txpool RPC methods, now you can fast send transaction sequencely. For example:
1
for(let i = 0; i < 100; i++) {
2
let hash = await conflux.cfx.sendTransaction({
3
from: account,
4
to: 'cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp',
5
value: 1
6
});
7
console.log(`TX hash: ${hash}`);
8
}
Copied!
Note the max sequence transaction send count can not surpass 2000

Readable ABI support

1
const tokenAbi = [
2
// Some details about the token
3
"function name() view returns (string)",
4
"function symbol() view returns (string)",
5
6
// Get the account balance
7
"function balanceOf(address) view returns (uint)",
8
9
// Send some of your tokens to someone else
10
"function transfer(address to, uint amount)",
11
12
// An event triggered whenever anyone transfers to someone else
13
"event Transfer(address indexed from, address indexed to, uint amount)"
14
];
15
16
const contract = conflux.Contract({
17
abi: tokenAbi,
18
address: 'cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp' // use a valid token address here
19
});
20
21
const balance = await contract.balanceOf('cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp');
Copied!
Last modified 4mo ago