quantum-coin-js-sdk 1.0.6
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/.github/workflows/publish-npmjs.yaml +22 -0
- package/.gitignore +2 -0
- package/README.md +716 -0
- package/example/README.md +3 -0
- package/example/example.js +195 -0
- package/example/package-lock.json +127 -0
- package/example/package.json +15 -0
- package/index.js +1178 -0
- package/package.json +33 -0
- package/wasm_exec.js +561 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
const qcsdk = require('qc-sdk');
|
|
2
|
+
const ethers = require('ethers');
|
|
3
|
+
|
|
4
|
+
//Initialize the client configuration
|
|
5
|
+
var clientConfigVal = new qcsdk.Config("https://t4-relayread.quantumcoin.org", "https://t4-relaywrite.quantumcoin.org", 310324, "", ""); //Testnet T4
|
|
6
|
+
//Testnet T4 Block Explorer: https://t4.scan.quantumcoin.org
|
|
7
|
+
|
|
8
|
+
//For mainnet, use the following configuration
|
|
9
|
+
//var clientConfigVal = new qcsdk.Config("https://relayread.quantumcoin.org", "https://relaywrite.quantumcoin.org", 123123, "", ""); //Mainnet
|
|
10
|
+
//Mainnet Block Explorer: https://scan.quantumcoin.org
|
|
11
|
+
|
|
12
|
+
//Initialize the SDK
|
|
13
|
+
qcsdk.initialize(clientConfigVal).then((initResult) => {
|
|
14
|
+
if (initResult === false) {
|
|
15
|
+
console.error("Initialize failed");
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
console.log("Initialize succeeded");
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
//Get the account details
|
|
22
|
+
let address = "0x0000000000000000000000000000000000000000000000000000000000001000"; //Just an example address https://t4.scan.quantumcoin.org/account/0x0000000000000000000000000000000000000000000000000000000000001000
|
|
23
|
+
|
|
24
|
+
console.log("getAccountDetails " + address);
|
|
25
|
+
qcsdk.getAccountDetails(address).then((accountDetailsResult) => {
|
|
26
|
+
if (accountDetailsResult === null) {
|
|
27
|
+
console.error("getAccountDetails failed : accountDetailsResult is null");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (accountDetailsResult.resultCode !== 0) {
|
|
32
|
+
console.log("getAccountDetails failed. resultCode is " + accountDetailsResult.resultCode);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (accountDetailsResult.accountDetails === null) {
|
|
37
|
+
console.error("getAccountDetails failed : accountDetails is null");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log("getAccountDetails succeeded:");
|
|
42
|
+
|
|
43
|
+
console.log(" address: " + accountDetailsResult.accountDetails.address);
|
|
44
|
+
|
|
45
|
+
console.log(" balance (wei): " + accountDetailsResult.accountDetails.balance);
|
|
46
|
+
var etherValue = ethers.formatEther(accountDetailsResult.accountDetails.balance)
|
|
47
|
+
console.log(" balance coins: " + etherValue);
|
|
48
|
+
|
|
49
|
+
console.log(" nonce: " + accountDetailsResult.accountDetails.nonce);
|
|
50
|
+
|
|
51
|
+
console.log(" as of blockNumber: " + accountDetailsResult.accountDetails.blockNumber);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
//Get the transaction details
|
|
55
|
+
let txnHash = "0x710cc145eea254c3db9857b42f0b576f4159ac48a23bfc0c480c341e90a40376"; //Just an example transaction hash https://t4.scan.quantumcoin.org/txn/0x710cc145eea254c3db9857b42f0b576f4159ac48a23bfc0c480c341e90a40376
|
|
56
|
+
|
|
57
|
+
console.log("getTransactionDetails " + txnHash);
|
|
58
|
+
qcsdk.getTransactionDetails(txnHash).then((transactionDetailsResult) => {
|
|
59
|
+
if (transactionDetailsResult === null) {
|
|
60
|
+
console.error("getTransactionDetails failed : transactionDetailsResult is null");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (transactionDetailsResult.resultCode !== 0) {
|
|
65
|
+
console.log("getTransactionDetails failed. resultCode is " + transactionDetailsResult.resultCode);
|
|
66
|
+
if (transactionDetailsResult.response !== null && transactionDetailsResult.response.status === 404) {
|
|
67
|
+
console.log("this transaction does not exist or has been discarded");
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (transactionDetailsResult.transactionDetails === null) {
|
|
73
|
+
console.error("getTransactionDetails failed : transactionDetails is null");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
console.log(" blockHash " + transactionDetailsResult.transactionDetails.blockHash);
|
|
78
|
+
console.log(" blockNumber " + transactionDetailsResult.transactionDetails.blockNumber);
|
|
79
|
+
console.log(" from " + transactionDetailsResult.transactionDetails.from);
|
|
80
|
+
console.log(" gas " + transactionDetailsResult.transactionDetails.gas);
|
|
81
|
+
console.log(" gasPrice " + transactionDetailsResult.transactionDetails.gasPrice);
|
|
82
|
+
console.log(" hash " + transactionDetailsResult.transactionDetails.hash);
|
|
83
|
+
console.log(" input " + transactionDetailsResult.transactionDetails.input);
|
|
84
|
+
console.log(" nonce " + transactionDetailsResult.transactionDetails.nonce);
|
|
85
|
+
console.log(" to " + transactionDetailsResult.transactionDetails.to);
|
|
86
|
+
console.log(" value " + transactionDetailsResult.transactionDetails.value);
|
|
87
|
+
|
|
88
|
+
if (transactionDetailsResult.transactionDetails.receipt === null) {
|
|
89
|
+
console.log("transaction receipt is null. This indiciates the transaction is not yet registered in the blockchain. This transaction may be pending.")
|
|
90
|
+
} else {
|
|
91
|
+
console.log(" cumulativeGasUsed " + transactionDetailsResult.transactionDetails.receipt.cumulativeGasUsed);
|
|
92
|
+
console.log(" effectiveGasPrice " + transactionDetailsResult.transactionDetails.receipt.effectiveGasPrice);
|
|
93
|
+
console.log(" gasUsed " + transactionDetailsResult.transactionDetails.receipt.gasUsed);
|
|
94
|
+
console.log(" hash " + transactionDetailsResult.transactionDetails.receipt.hash);
|
|
95
|
+
console.log(" type " + transactionDetailsResult.transactionDetails.receipt.type);
|
|
96
|
+
console.log(" status " + transactionDetailsResult.transactionDetails.receipt.status);
|
|
97
|
+
|
|
98
|
+
if (transactionDetailsResult.transactionDetails.receipt.status === "0x1") {
|
|
99
|
+
console.log(" Transaction has succeeded!!!");
|
|
100
|
+
} else {
|
|
101
|
+
console.log(" Transaction has failed!!!");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
//Get the latest block details
|
|
108
|
+
console.log("getLatestBlockDetails");
|
|
109
|
+
qcsdk.getLatestBlockDetails(address).then((latestBlockDetailsResult) => {
|
|
110
|
+
if (latestBlockDetailsResult === null) {
|
|
111
|
+
console.error(" getLatestBlockDetails failed : latestBlockDetailsResult is null");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (latestBlockDetailsResult.resultCode !== 0) {
|
|
116
|
+
console.log(" getLatestBlockDetails failed. resultCode is " + latestBlockDetailsResult.resultCode);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (latestBlockDetailsResult.blockDetails === null) {
|
|
121
|
+
console.error(" getLatestBlockDetails failed : blockDetails is null");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
console.log(" getLatestBlockDetails succeeded:");
|
|
126
|
+
console.log(" latest block number: " + latestBlockDetailsResult.blockDetails.blockNumber);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
//Create a new wallet
|
|
131
|
+
var wallet1 = qcsdk.newWallet();
|
|
132
|
+
if (wallet1 === null) {
|
|
133
|
+
console.log("creating a new wallet failed");
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
console.log("New wallet address is: " + wallet1.address);
|
|
137
|
+
|
|
138
|
+
//Serialize wallet to a string (You should encrypt the string before saving it to disk or a database.)
|
|
139
|
+
var walletJson = qcsdk.serializeWallet(wallet1);
|
|
140
|
+
if (walletJson === null) {
|
|
141
|
+
console.log("serializeWallet failed");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
//Deserialzie a wallet from the serialized wallet
|
|
146
|
+
var wallet2 = qcsdk.deserializeWallet(walletJson);
|
|
147
|
+
console.log("Deserialized wallet address is: " + wallet2.address);
|
|
148
|
+
|
|
149
|
+
//Validate that a wallet address is correct
|
|
150
|
+
console.log("isAddressValid (expected true)" + qcsdk.isAddressValid(wallet1.address)); //should print true
|
|
151
|
+
console.log("isAddressValid (expected false)" + qcsdk.isAddressValid("asfasdfasdfs")); //should print false
|
|
152
|
+
|
|
153
|
+
//Send coins
|
|
154
|
+
//First get account details nonce
|
|
155
|
+
console.log("sendCoins getAccountDetails " + address);
|
|
156
|
+
qcsdk.getAccountDetails(address).then((accountDetailsResult) => {
|
|
157
|
+
if (accountDetailsResult === null) {
|
|
158
|
+
console.error(" sendCoins getAccountDetails failed : accountDetailsResult is null");
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (accountDetailsResult.resultCode !== 0) {
|
|
163
|
+
console.log(" sendCoins getAccountDetails failed. resultCode is " + accountDetailsResult.resultCode);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (accountDetailsResult.accountDetails === null) {
|
|
168
|
+
console.error(" sendCoins getAccountDetails failed : accountDetails is null");
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
var toAddress = "0x8293cd9b6ac502d2fe077b0c157dad39f36a5e546525b053151dced633634612";
|
|
173
|
+
var nonce = accountDetailsResult.accountDetails.nonce;
|
|
174
|
+
var coinsInWei = "1000";
|
|
175
|
+
|
|
176
|
+
qcsdk.sendCoins(wallet2, toAddress, coinsInWei, nonce).then((sendResult) => {
|
|
177
|
+
if (sendResult === null) {
|
|
178
|
+
console.error(" sendCoins failed : sendResult is null");
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (sendResult.resultCode !== 0) {
|
|
183
|
+
console.log(" sendCoins failed. resultCode is " + sendResult.resultCode);
|
|
184
|
+
if (sendResult.response !== null) {
|
|
185
|
+
console.log(" sendCoin response statusText " + JSON.stringify(sendResult.response.statusText));
|
|
186
|
+
console.log(" ensure account has adequate gas and nonce is correct");
|
|
187
|
+
}
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
console.log(" sendCoin succeeded. This does not necessarily mean that the transaction has succeded. txnHash " + sendResult.txnHash);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "qc-sdk-example",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "qc-sdk-example",
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"ethers": "^6.13.4",
|
|
13
|
+
"qc-sdk": "^1.0.2"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"node_modules/@adraffy/ens-normalize": {
|
|
17
|
+
"version": "1.10.1",
|
|
18
|
+
"resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.10.1.tgz",
|
|
19
|
+
"integrity": "sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw=="
|
|
20
|
+
},
|
|
21
|
+
"node_modules/@noble/curves": {
|
|
22
|
+
"version": "1.2.0",
|
|
23
|
+
"resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz",
|
|
24
|
+
"integrity": "sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@noble/hashes": "1.3.2"
|
|
27
|
+
},
|
|
28
|
+
"funding": {
|
|
29
|
+
"url": "https://paulmillr.com/funding/"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"node_modules/@noble/hashes": {
|
|
33
|
+
"version": "1.3.2",
|
|
34
|
+
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz",
|
|
35
|
+
"integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==",
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">= 16"
|
|
38
|
+
},
|
|
39
|
+
"funding": {
|
|
40
|
+
"url": "https://paulmillr.com/funding/"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"node_modules/@types/node": {
|
|
44
|
+
"version": "22.7.5",
|
|
45
|
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz",
|
|
46
|
+
"integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==",
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"undici-types": "~6.19.2"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"node_modules/aes-js": {
|
|
52
|
+
"version": "4.0.0-beta.5",
|
|
53
|
+
"resolved": "https://registry.npmjs.org/aes-js/-/aes-js-4.0.0-beta.5.tgz",
|
|
54
|
+
"integrity": "sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q=="
|
|
55
|
+
},
|
|
56
|
+
"node_modules/ethers": {
|
|
57
|
+
"version": "6.13.4",
|
|
58
|
+
"resolved": "https://registry.npmjs.org/ethers/-/ethers-6.13.4.tgz",
|
|
59
|
+
"integrity": "sha512-21YtnZVg4/zKkCQPjrDj38B1r4nQvTZLopUGMLQ1ePU2zV/joCfDC3t3iKQjWRzjjjbzR+mdAIoikeBRNkdllA==",
|
|
60
|
+
"funding": [
|
|
61
|
+
{
|
|
62
|
+
"type": "individual",
|
|
63
|
+
"url": "https://github.com/sponsors/ethers-io/"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"type": "individual",
|
|
67
|
+
"url": "https://www.buymeacoffee.com/ricmoo"
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@adraffy/ens-normalize": "1.10.1",
|
|
72
|
+
"@noble/curves": "1.2.0",
|
|
73
|
+
"@noble/hashes": "1.3.2",
|
|
74
|
+
"@types/node": "22.7.5",
|
|
75
|
+
"aes-js": "4.0.0-beta.5",
|
|
76
|
+
"tslib": "2.7.0",
|
|
77
|
+
"ws": "8.17.1"
|
|
78
|
+
},
|
|
79
|
+
"engines": {
|
|
80
|
+
"node": ">=14.0.0"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"node_modules/pqc-js-sdk": {
|
|
84
|
+
"version": "1.0.0",
|
|
85
|
+
"resolved": "https://registry.npmjs.org/pqc-js-sdk/-/pqc-js-sdk-1.0.0.tgz",
|
|
86
|
+
"integrity": "sha512-7Q5YlFvaXoP+MK+yn4KH4MYvJDkyGoGUU/zKYsRxR1mVqddqGUsGvz2JTsfH5B/Gkk97gMMh3PQ7MmkM8iJA5Q=="
|
|
87
|
+
},
|
|
88
|
+
"node_modules/qc-sdk": {
|
|
89
|
+
"version": "1.0.4",
|
|
90
|
+
"resolved": "https://registry.npmjs.org/qc-sdk/-/qc-sdk-1.0.4.tgz",
|
|
91
|
+
"integrity": "sha512-Nj3DAF4JkyJ2XPjToY5l/i5yBUOxY5Cs4boDeqmFOwvt3qXldCS5fTAOBBpDKQLFYJOnI/CmfRt5hnskIP0GIg==",
|
|
92
|
+
"dependencies": {
|
|
93
|
+
"pqc-js-sdk": "^1.0.0"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"node_modules/tslib": {
|
|
97
|
+
"version": "2.7.0",
|
|
98
|
+
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz",
|
|
99
|
+
"integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA=="
|
|
100
|
+
},
|
|
101
|
+
"node_modules/undici-types": {
|
|
102
|
+
"version": "6.19.8",
|
|
103
|
+
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
|
|
104
|
+
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw=="
|
|
105
|
+
},
|
|
106
|
+
"node_modules/ws": {
|
|
107
|
+
"version": "8.17.1",
|
|
108
|
+
"resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz",
|
|
109
|
+
"integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==",
|
|
110
|
+
"engines": {
|
|
111
|
+
"node": ">=10.0.0"
|
|
112
|
+
},
|
|
113
|
+
"peerDependencies": {
|
|
114
|
+
"bufferutil": "^4.0.1",
|
|
115
|
+
"utf-8-validate": ">=5.0.2"
|
|
116
|
+
},
|
|
117
|
+
"peerDependenciesMeta": {
|
|
118
|
+
"bufferutil": {
|
|
119
|
+
"optional": true
|
|
120
|
+
},
|
|
121
|
+
"utf-8-validate": {
|
|
122
|
+
"optional": true
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "qc-sdk-example",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Quantum Coin SDK Example",
|
|
5
|
+
"main": "example.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "Quantum Coin Community",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"ethers": "^6.13.4",
|
|
13
|
+
"qc-sdk": "^1.0.2"
|
|
14
|
+
}
|
|
15
|
+
}
|