# 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](/js-conflux-sdk/v2.0_changes.md) 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:

```js
async function main() {
  const conflux = new Conflux({
    url: 'https://test.confluxrpc.com',
    networkId: 1
  });
  const status = await conflux.pos.getStatus();
  console.log('Current PoS status: ', status);
  /*
  {
    epoch: 29,
    latestCommitted: 1725,
    latestTxNumber: '0x1e36',
    latestVoted: 1728,
    pivotDecision: {
      blockHash: '0xc8c2c58ef952f48adf00d6204d6e930f23aee26c6b9a903820bea1c012f72f3e',
      height: 120480
    }
  }
  */
}
```

Check [PoS RPC documentation](/js-conflux-sdk/v2.0_changes.md) for the complete method list.

And previous `cfx` RPC methods are also been moved to their own namespace, for example:

```js
const balance = await conflux.cfx.getBalance('cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp');
```

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:

```js
const batcher = conflux.BatchRequest();
batcher.add(conflux.cfx.getStatus.request());
batcher.add(conflux.cfx.getBalance.request('cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp'));

const [status, balance] = await batcher.execute();
```

Check [here](/js-conflux-sdk/docs/batch_rpc.md) 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

```html
<script type="text/javascript">
  const conflux = new window.Conflux.Conflux({
    url: 'https://test.confluxrpc.com',
    logger: console,
    networkId: 1,
  });
</script>
```

Currently:

```html
<script type="text/javascript">
  const conflux = new window.TreeGraph.Conflux({
    url: 'https://test.confluxrpc.com',
    logger: console,
    networkId: 1,
  });
</script>
```

## Enable fast send transaction

If your RPC endpoint support `txpool` RPC methods, now you can fast send transaction sequencely. For example:

```js
for(let i = 0; i < 100; i++) {
  let hash = await conflux.cfx.sendTransaction({
    from: account,
    to: 'cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp',
    value: 1
  });
  console.log(`TX hash: ${hash}`);
}
```

Note the max sequence transaction send count can not surpass `2000`

## Readable ABI support

```js
const tokenAbi = [
  // Some details about the token
  "function name() view returns (string)",
  "function symbol() view returns (string)",

  // Get the account balance
  "function balanceOf(address) view returns (uint)",

  // Send some of your tokens to someone else
  "function transfer(address to, uint amount)",

  // An event triggered whenever anyone transfers to someone else
  "event Transfer(address indexed from, address indexed to, uint amount)"
];

const contract = conflux.Contract({
  abi: tokenAbi,
  address: 'cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp' // use a valid token address here
});

const balance = await contract.balanceOf('cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp');
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://confluxnetwork.gitbook.io/js-conflux-sdk/v2.0_changes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
