1 | # js-conflux-sdk
|
2 |
|
3 | JavaScript Conflux Software Development Kit
|
4 |
|
5 | ## Installation
|
6 |
|
7 | `npm install js-conflux-sdk`
|
8 |
|
9 | ## Usage
|
10 |
|
11 | [api document](https://github.com/Conflux-Chain/js-conflux-sdk/blob/master/api.md)
|
12 |
|
13 | ### Nodejs
|
14 | ```javascript
|
15 | const { Conflux } = require('js-conflux-sdk');
|
16 |
|
17 | async function main() {
|
18 | const cfx = new Conflux({
|
19 | url: 'http://testnet-jsonrpc.conflux-chain.org:12537',
|
20 | defaultGasPrice: 100,
|
21 | defaultGas: 1000000,
|
22 | logger: console,
|
23 | });
|
24 |
|
25 | const balance = await cfx.getBalance('0xbbd9e9be525ab967e633bcdaeac8bd5723ed4d6b');
|
26 | console.log(balance); // 937499420597305000n
|
27 | }
|
28 |
|
29 | main();
|
30 | ```
|
31 | require deep nested file/dir
|
32 |
|
33 | ``` javascript
|
34 | const util = require('js-conflux-sdk/lib/util');
|
35 | ```
|
36 |
|
37 | ### Frontend
|
38 |
|
39 | #### esm
|
40 | ``` javascript
|
41 | import { Conflux } from 'js-conflux-sdk';
|
42 | import { util } from 'js-conflux-sdk/esm/util';
|
43 | ```
|
44 |
|
45 | Note: This assumes bundler will read the [package.json browser
|
46 | field](https://docs.npmjs.com/files/package.json#browser) as module entry. For
|
47 | bundlers don't support that, additional configurations needs to be add to
|
48 | support that. Please checkout the bundlers documentation.
|
49 |
|
50 | #### umd
|
51 | ``` javascript
|
52 | import { Conflux } from 'js-conflux-sdk/dist/js-conflux-sdk.umd.min.js';
|
53 | ```
|
54 |
|
55 | or
|
56 |
|
57 | ``` html
|
58 | <script type="text/javascript" src="node_modules/js-conflux-sdk/dist/js-conflux-sdk.umd.min.js"></script>
|
59 | <script type="text/javascript">
|
60 | const cfx = new window.Conflux.Conflux({
|
61 | url: 'http://testnet-jsonrpc.conflux-chain.org:12537',
|
62 | defaultGasPrice: 100,
|
63 | defaultGas: 1000000,
|
64 | logger: console,
|
65 | });
|
66 | </script>
|
67 | ```
|
68 |
|
69 | ## Example
|
70 |
|
71 | [example](https://github.com/Conflux-Chain/js-conflux-sdk/tree/master/example)
|