@carbonx3/cx3.js 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -81
- package/index.js +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
# @carbonx3/cx3.js
|
|
1
|
+
# @carbonx3/cx3.js
|
|
2
2
|
|
|
3
|
-
Official
|
|
3
|
+
Official **Node.js** client (**CX3js**) for [CarbonX3 Green Chain](https://carbonx3.com/).
|
|
4
4
|
|
|
5
5
|
Talks to the node over **REST + JSON** (`/api/v1/...`) with named method params.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
|
10
|
-
|
|
11
|
-
| `
|
|
12
|
-
| `
|
|
7
|
+
The **browser** client is the **CX3 IIFE**: `<script src="cx3.min.js"></script>` (`window.cx3`). Do not `require` this package in a page.
|
|
8
|
+
|
|
9
|
+
| Export | Role |
|
|
10
|
+
|--------|------|
|
|
11
|
+
| `Cx3Provider` | HTTP client (`{node}/api/v1`) |
|
|
12
|
+
| `Cx3Wallet` | secp256k1 signing (deploy / send / native CX3) |
|
|
13
|
+
| `Contract` / `provider.getContract` | ABI-bound calls |
|
|
14
|
+
| `Cx3TokenFactory` | Standard deploys (CX30–CX3192, CX337–CX341) |
|
|
13
15
|
|
|
14
16
|
## Install
|
|
15
17
|
|
|
16
18
|
```bash
|
|
17
|
-
# when published
|
|
18
19
|
npm install @carbonx3/cx3.js
|
|
19
|
-
|
|
20
|
-
# from monorepo root
|
|
21
|
-
npm install ./CX3Web3JS
|
|
22
|
-
|
|
23
|
-
# or inside another package
|
|
24
|
-
npm install file:../CX3Web3JS
|
|
25
20
|
```
|
|
26
21
|
|
|
27
22
|
Node.js **18+** (native `fetch`).
|
|
@@ -29,39 +24,17 @@ Node.js **18+** (native `fetch`).
|
|
|
29
24
|
## Quick start
|
|
30
25
|
|
|
31
26
|
```javascript
|
|
32
|
-
const {
|
|
33
|
-
Cx3Provider,
|
|
34
|
-
Cx3Wallet,
|
|
35
|
-
Cx3TokenFactory,
|
|
36
|
-
readCallValue
|
|
37
|
-
} = require("@carbonx3/cx3.js");
|
|
38
|
-
|
|
39
|
-
const provider = new Cx3Provider(process.env.CX3_NODE_URL, {
|
|
40
|
-
auth: {
|
|
41
|
-
user: process.env.CX3_INTERNAL_AUTH_USER,
|
|
42
|
-
pass: process.env.CX3_INTERNAL_AUTH_PASS
|
|
43
|
-
}
|
|
44
|
-
// or: apiKey: process.env.CX3_API_KEY // empty = public (any wallet); cx3wk_ = that wallet only
|
|
45
|
-
});
|
|
27
|
+
const { Cx3Provider, Cx3Wallet, Cx3TokenFactory } = require("@carbonx3/cx3.js");
|
|
46
28
|
|
|
29
|
+
const provider = new Cx3Provider("https://your-green-chain-node");
|
|
47
30
|
const wallet = new Cx3Wallet(process.env.CX3_PRIVATE_KEY, provider);
|
|
48
|
-
await wallet.bindApiKey();
|
|
49
31
|
|
|
50
|
-
// Read
|
|
51
32
|
const token = await provider.getContract(process.env.CONTRACT_ADDRESS, null, wallet);
|
|
52
33
|
const balance = await token.balanceOf(wallet.address);
|
|
53
|
-
console.log("balance", balance);
|
|
54
34
|
|
|
55
|
-
const cx3Balance = await provider.getBalance(wallet.address);
|
|
56
|
-
|
|
57
|
-
// Write
|
|
58
35
|
const tx = await token.transfer("0xRecipient…", "1000000000000000000");
|
|
59
36
|
await tx.wait();
|
|
60
37
|
|
|
61
|
-
await wallet.pauseContract(process.env.CONTRACT_ADDRESS);
|
|
62
|
-
await wallet.transferNative("0xRecipient…", 1);
|
|
63
|
-
|
|
64
|
-
// Deploy CX30
|
|
65
38
|
const factory = new Cx3TokenFactory(wallet);
|
|
66
39
|
const deployed = await factory.deployCX30({
|
|
67
40
|
name: "My Token",
|
|
@@ -72,67 +45,56 @@ const deployed = await factory.deployCX30({
|
|
|
72
45
|
console.log(deployed.contractAddress);
|
|
73
46
|
```
|
|
74
47
|
|
|
75
|
-
##
|
|
48
|
+
## Connect
|
|
76
49
|
|
|
77
|
-
|
|
50
|
+
**1. Green Chain node (usual case)** — pass the node URL only. No username, password, or API key.
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
const provider = new Cx3Provider("https://your-green-chain-node");
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**2. Your own node** — add HTTP Basic **only if that node requires it**. If it does not, skip this and keep option 1.
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
const provider = new Cx3Provider("https://your-node", {
|
|
60
|
+
auth: {
|
|
61
|
+
user: process.env.CX3_INTERNAL_AUTH_USER,
|
|
62
|
+
pass: process.env.CX3_INTERNAL_AUTH_PASS
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Optional wallet API key
|
|
68
|
+
|
|
69
|
+
Leave unset for **public** access (any wallet). Set a `cx3wk_…` key only to lock this client to that wallet. Never put an API key in browser JavaScript.
|
|
70
|
+
|
|
71
|
+
## Signing
|
|
72
|
+
|
|
73
|
+
Digests are **UTF-8 strings**, then `sha256` + **secp256k1**:
|
|
78
74
|
|
|
79
75
|
- Deploy: `deploy|{owner}|{standard}|{name}|{symbol}|{decimals}|{initialSupply}|{timestamp}`
|
|
80
76
|
- Send: `{contractAddress}|{method}|{JSON.stringify(params)}|{fromAddress}`
|
|
81
77
|
- Owner: `{action}|{address}|{owner}|{timestamp}`
|
|
82
|
-
- Native CX3:
|
|
78
|
+
- Native CX3: `wallet.transferNative(to, amount)`
|
|
83
79
|
|
|
84
80
|
Address = `0x` + last 20 bytes of `sha256(uncompressedPublicKey)`.
|
|
85
81
|
|
|
86
82
|
## ABI-bound methods
|
|
87
83
|
|
|
88
|
-
Supports:
|
|
89
|
-
|
|
90
84
|
1. Standard interface JSON (`methods.balanceOf.type = "view"`)
|
|
91
85
|
2. Compiler flat ABI (`[{ type: "function", name, inputs, stateMutability }]`)
|
|
92
86
|
|
|
93
|
-
Positional args map to ABI input names:
|
|
94
|
-
|
|
95
87
|
```javascript
|
|
96
|
-
await token.balanceOf(owner);
|
|
97
|
-
await token.transfer(to, amount);
|
|
88
|
+
await token.balanceOf(owner);
|
|
89
|
+
await token.transfer(to, amount);
|
|
98
90
|
await token.call("balanceOf", { account: owner });
|
|
99
91
|
```
|
|
100
92
|
|
|
101
|
-
##
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
CX3_NODE_URL=https://your-node
|
|
105
|
-
CX3_INTERNAL_AUTH_USER=cx3-internal
|
|
106
|
-
CX3_INTERNAL_AUTH_PASS=…
|
|
107
|
-
CX3_API_KEY=cx3wk_… # optional; empty = public (any wallet); set = that wallet only (X-Api-Key)
|
|
108
|
-
CX3_PRIVATE_KEY=… # 64-hex or 0x-prefixed
|
|
109
|
-
CX3_CHAIN_ID=cx3-dev # native transfer payload (default)
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## Package layout
|
|
93
|
+
## Docs
|
|
113
94
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
index.js # public API
|
|
117
|
-
index.d.ts
|
|
118
|
-
src/
|
|
119
|
-
provider.js
|
|
120
|
-
wallet.js
|
|
121
|
-
contract.js
|
|
122
|
-
factory.js
|
|
123
|
-
crypto.js
|
|
124
|
-
digest.js
|
|
125
|
-
…
|
|
126
|
-
test/
|
|
127
|
-
```
|
|
95
|
+
- [CX3js SDK](https://cx3script.com/docs?doc=cx3js-sdk)
|
|
96
|
+
- [CarbonX3 Green Chain](https://carbonx3.com/)
|
|
128
97
|
|
|
129
98
|
## License
|
|
130
99
|
|
|
131
100
|
UNLICENSED — Mersolution Technology Ltd.
|
|
132
|
-
|
|
133
|
-
## Docs
|
|
134
|
-
|
|
135
|
-
CX3Script documentation site (sidebar **cx3.js SDK**):
|
|
136
|
-
|
|
137
|
-
- Monorepo: `CX3VM-WebSites/cx3docs/docs/cx3js-sdk.md`
|
|
138
|
-
- Local: `/CX3VM-WebSites/docs?doc=cx3js-sdk`
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbonx3/cx3.js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "CarbonX3 Green Chain JavaScript SDK (CX3js) - Provider / Wallet / Contract over REST + JSON",
|
|
5
|
+
"homepage": "https://cx3script.com/docs?doc=cx3js-sdk",
|
|
5
6
|
"publishConfig": {
|
|
6
7
|
"access": "public"
|
|
7
8
|
},
|