Skip to content

Commit

Permalink
Add support for new CIP 37 address (#104)
Browse files Browse the repository at this point in the history
* new checksum address

* export PrivateKeyAccount and addressUtil

* add address.simplifyCfxAddress method

* Conflux add static method create

* update block trace formatter
  • Loading branch information
Pana authored Feb 2, 2021
1 parent bbb903f commit 968e8e5
Show file tree
Hide file tree
Showing 41 changed files with 11,883 additions and 541 deletions.
13 changes: 13 additions & 0 deletions CHANGE_LOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# change log

## v1.5.0

* `Conflux`'s option can pass `networkId` now, and add a new method `updateNetworkId` to sync networkId from RPC.
* `format.address` will return new CIP37 addresses, if you pass a hex address, `networkId` should also be passed as second parameter
* add new method `format.hexAddress` to format hex address
* Wallet's constructor add a parameter `networkId`
* PrivateKeyAccount `constructor`, `decrypt`, `random` need one more parameter `networkId`
* `Transaction`, `Message` `sign` method need one more parameter `networkId`
* Conflux's get methods will return new address, and same to contract method returned address.
* `getSupplyInfo` response add new field `totalCirculating`
* `getStatus` response add new field `networkId`


## v1.1.7

* Add RPC method `traceBlock` to `Conflux` which can used to get block's execution trace
Expand Down
53 changes: 44 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,46 @@

JavaScript Conflux Software Development Kit

## 1.0 Key features
## 1.5 Key features
v1.5 add support for [CIP37](https://github.com/Conflux-Chain/CIPs/blob/master/CIPs/cip-37.md) address.
And only work with `conflux-rust v1.1.1` or above.

1. Add `cfx.wallet` to manage multiple accounts, which has replace v0.13's `cfx.Account`.
2. Add `cfx.InternalContract(name)` to interact with Conflux internal contracts.
3. Add websocket provider, support pub/sub
4. Provide `Drip` to easily convert unit between CFX, Drip, Gdrip
5. Use `JSBI` for browser, native `BigInt` for Node.js
```sh
# For now you can install it with `next` tag
$ npm install js-conflux-sdk@next
```

The biggest difference you `must to know` is class `Conflux`'s init option add a new field `networkId`.
If you still want use hex40 address when invoke RPC methods, `networkId must be set`,
only with `networkId` conflux can firgure out a right CIP37 address from hex40 address.

There are two way you can set it. You can specify `networkId` when initiate the conflux object
```js
const conflux = new Conflux({
url: 'https://test.confluxrpc.org/v2',
networkId: 1
});
```

Or you can create a `Conflux` instance with `create` static method
```js
const conflux = await Conflux.create({
url: 'https://test.confluxrpc.org/v2',
});
```

If you forgot to set networkId, you will see warning about it.

Another big change is `format.address` will return CIP-37 address.

```js
format.address('0x0123456789012345678901234567890123456789', 1) // second parameter networkId is required when passing a hex40 address
// "cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp"
format.address('cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp')
// "cfxtest:aaawgvnhveawgvnhveawgvnhveawgvnhvey1umfzwp"
```

Check the [complete changelog](./CHANGE_LOG.md)
Check detail in the [complete changelog](./CHANGE_LOG.md)

## Quick Usage

Expand All @@ -23,7 +54,8 @@ Check the [complete changelog](./CHANGE_LOG.md)
const { Conflux } = require('js-conflux-sdk');

const conflux = new Conflux({
url: 'http://test.confluxrpc.org',
url: 'https://test.confluxrpc.org/v2',
networkId: 1,
logger: console, // for debug
});
```
Expand Down Expand Up @@ -52,8 +84,9 @@ or
<script type="text/javascript" src="node_modules/js-conflux-sdk/dist/js-conflux-sdk.umd.min.js"></script>
<script type="text/javascript">
const conflux = new window.Conflux.Conflux({
url: 'http://test.confluxrpc.org',
url: 'https://test.confluxrpc.org/v2',
logger: console,
networkId: 1,
});
</script>
```
Expand All @@ -63,8 +96,10 @@ or
* [Overview](./docs/overview.md)
* [Complete document for send transaction](./docs/how_to_send_tx.md)
* [Interacting with contract](./docs/interact_with_contract.md)
* [SDK support for CIP37 address](./docs/conflux_checksum_address.md)
* [API](./docs/api.md)
* [Conflux Official document](https://developer.conflux-chain.org/docs/introduction/en/conflux_overview)
* [Conflux RPC endpoints](https://github.com/conflux-fans/conflux-rpc-endpoints)

## TODO

Expand Down
Loading

0 comments on commit 968e8e5

Please sign in to comment.