quantum-coin-js-sdk 1.0.6 → 1.0.7
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 +7 -7
- package/example/README.md +6 -0
- package/example/example.js +4 -3
- package/example/package-lock.json +5 -5
- package/example/package.json +1 -1
- package/index.js +32 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Quantum Coin JS SDK provides functionality to interact with the Quantum Coin Blo
|
|
|
5
5
|
|
|
6
6
|
**Example**
|
|
7
7
|
```js
|
|
8
|
-
Installation:
|
|
8
|
+
Installation:
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
* [quantum-coin-js-sdk](#module_quantum-coin-js-sdk)
|
|
@@ -77,8 +77,8 @@ Installation:
|
|
|
77
77
|
* [~getLatestBlockDetails()](#module_quantum-coin-js-sdk..getLatestBlockDetails) ⇒ <code>Promise.<BlockDetailsResult></code>
|
|
78
78
|
* [~getAccountDetails(address)](#module_quantum-coin-js-sdk..getAccountDetails) ⇒ <code>Promise.<AccountDetailsResult></code>
|
|
79
79
|
* [~getTransactionDetails(txnHash)](#module_quantum-coin-js-sdk..getTransactionDetails) ⇒ <code>Promise.<TransactionDetailsResult></code>
|
|
80
|
-
* [~signSendCoinTransaction(wallet, toAddress,
|
|
81
|
-
* [~sendCoins(wallet, toAddress,
|
|
80
|
+
* [~signSendCoinTransaction(wallet, toAddress, coins, nonce)](#module_quantum-coin-js-sdk..signSendCoinTransaction) ⇒ <code>SignResult</code>
|
|
81
|
+
* [~sendCoins(wallet, toAddress, coins, nonce)](#module_quantum-coin-js-sdk..sendCoins) ⇒ <code>Promise.<SendResult></code>
|
|
82
82
|
|
|
83
83
|
<a name="module_quantum-coin-js-sdk..Config"></a>
|
|
84
84
|
|
|
@@ -686,7 +686,7 @@ The getTransactionDetails function returns details of a transaction posted to th
|
|
|
686
686
|
|
|
687
687
|
<a name="module_quantum-coin-js-sdk..signSendCoinTransaction"></a>
|
|
688
688
|
|
|
689
|
-
### quantum-coin-js-sdk~signSendCoinTransaction(wallet, toAddress,
|
|
689
|
+
### quantum-coin-js-sdk~signSendCoinTransaction(wallet, toAddress, coins, nonce) ⇒ <code>SignResult</code>
|
|
690
690
|
The signSendCoinTransaction function returns a signed transaction.
|
|
691
691
|
|
|
692
692
|
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
@@ -696,12 +696,12 @@ The signSendCoinTransaction function returns a signed transaction.
|
|
|
696
696
|
| --- | --- | --- |
|
|
697
697
|
| wallet | <code>Wallet</code> | A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees. |
|
|
698
698
|
| toAddress | <code>string</code> | The address to which the coins should be sent. |
|
|
699
|
-
|
|
|
699
|
+
| coins | <code>string</code> | The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei |
|
|
700
700
|
| nonce | <code>number</code> | The nonce of the account retrieved by invoking the getAccountDetails function. You have to carefully manage state of the nonce to avoid sending the coins multiple times, such as when retrying sendCoins after a network error. |
|
|
701
701
|
|
|
702
702
|
<a name="module_quantum-coin-js-sdk..sendCoins"></a>
|
|
703
703
|
|
|
704
|
-
### quantum-coin-js-sdk~sendCoins(wallet, toAddress,
|
|
704
|
+
### quantum-coin-js-sdk~sendCoins(wallet, toAddress, coins, nonce) ⇒ <code>Promise.<SendResult></code>
|
|
705
705
|
The sendCoins function posts a send-coin transaction to the blockchain.
|
|
706
706
|
|
|
707
707
|
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
@@ -711,6 +711,6 @@ The sendCoins function posts a send-coin transaction to the blockchain.
|
|
|
711
711
|
| --- | --- | --- |
|
|
712
712
|
| wallet | <code>Wallet</code> | A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees. |
|
|
713
713
|
| toAddress | <code>string</code> | The address to which the coins should be sent. |
|
|
714
|
-
|
|
|
714
|
+
| coins | <code>string</code> | The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei |
|
|
715
715
|
| nonce | <code>number</code> | The nonce of the account retrieved by invoking the getAccountDetails function. You have to carefully manage state of the nonce to avoid sending the coins multiple times, such as when retrying sendCoins after a network error. |
|
|
716
716
|
|
package/example/README.md
CHANGED
package/example/example.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const qcsdk = require('
|
|
1
|
+
const qcsdk = require('quantum-coin-js-sdk');
|
|
2
2
|
const ethers = require('ethers');
|
|
3
3
|
|
|
4
4
|
//Initialize the client configuration
|
|
@@ -171,9 +171,10 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
|
|
|
171
171
|
|
|
172
172
|
var toAddress = "0x8293cd9b6ac502d2fe077b0c157dad39f36a5e546525b053151dced633634612";
|
|
173
173
|
var nonce = accountDetailsResult.accountDetails.nonce;
|
|
174
|
-
var
|
|
174
|
+
var coins = "10"; //in ethers and not in wei
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
console.log("Sending coins (wei) " + coins);
|
|
177
|
+
qcsdk.sendCoins(wallet2, toAddress, coins, nonce).then((sendResult) => { //carefully manage state of nonce when retrying on errors
|
|
177
178
|
if (sendResult === null) {
|
|
178
179
|
console.error(" sendCoins failed : sendResult is null");
|
|
179
180
|
return;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"ethers": "^6.13.4",
|
|
13
|
-
"
|
|
13
|
+
"quantum-coin-js-sdk": "^1.0.6"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"node_modules/@adraffy/ens-normalize": {
|
|
@@ -85,10 +85,10 @@
|
|
|
85
85
|
"resolved": "https://registry.npmjs.org/pqc-js-sdk/-/pqc-js-sdk-1.0.0.tgz",
|
|
86
86
|
"integrity": "sha512-7Q5YlFvaXoP+MK+yn4KH4MYvJDkyGoGUU/zKYsRxR1mVqddqGUsGvz2JTsfH5B/Gkk97gMMh3PQ7MmkM8iJA5Q=="
|
|
87
87
|
},
|
|
88
|
-
"node_modules/
|
|
89
|
-
"version": "1.0.
|
|
90
|
-
"resolved": "https://registry.npmjs.org/
|
|
91
|
-
"integrity": "sha512-
|
|
88
|
+
"node_modules/quantum-coin-js-sdk": {
|
|
89
|
+
"version": "1.0.6",
|
|
90
|
+
"resolved": "https://registry.npmjs.org/quantum-coin-js-sdk/-/quantum-coin-js-sdk-1.0.6.tgz",
|
|
91
|
+
"integrity": "sha512-knlmMCchtwWGancZpm3iKAIpK8aXDU6HwZ6QHol4Lhw8uNioXTFndcAdoJ3ZqVtsYlivg1r/5pG5W1E/5MCaSg==",
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"pqc-js-sdk": "^1.0.0"
|
|
94
94
|
}
|
package/example/package.json
CHANGED
package/index.js
CHANGED
|
@@ -9,10 +9,19 @@
|
|
|
9
9
|
* Installation:
|
|
10
10
|
* npm install quantum-coin-js-sdk --save
|
|
11
11
|
*
|
|
12
|
-
* Adding reference:
|
|
12
|
+
* //Adding reference:
|
|
13
13
|
* var qcsdk = require('quantum-coin-js-sdk');
|
|
14
14
|
*
|
|
15
|
+
* //Initialize the SDK first before invoking any other function
|
|
16
|
+
* var clientConfigVal = new qcsdk.Config("https://t4-relayread.quantumcoin.org", "https://t4-relaywrite.quantumcoin.org", 310324, "", ""); //Testnet T4 Block Explorer: https://t4.scan.quantumcoin.org
|
|
17
|
+
*
|
|
18
|
+
* qcsdk.initialize(clientConfigVal).then((initResult) => {
|
|
19
|
+
*
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
15
22
|
* Example Project: https://github.com/quantumcoinproject/quantum-coin-js-sdk/tree/main/example
|
|
23
|
+
*
|
|
24
|
+
*
|
|
16
25
|
*/
|
|
17
26
|
|
|
18
27
|
var fs = require('fs');
|
|
@@ -475,8 +484,14 @@ class TransactionDetailsResult {
|
|
|
475
484
|
}
|
|
476
485
|
|
|
477
486
|
function isLargeNumber(val) {
|
|
478
|
-
|
|
479
|
-
|
|
487
|
+
if (val === null) {
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
if (typeof val === 'string' || val instanceof String) {
|
|
491
|
+
var rgx = /^([0-9]+([.][0-9]*)?|[.][0-9]+)$/;
|
|
492
|
+
return Boolean(val.match(rgx));
|
|
493
|
+
}
|
|
494
|
+
return false;
|
|
480
495
|
}
|
|
481
496
|
|
|
482
497
|
async function InitAccountsWebAssembly() {
|
|
@@ -1008,16 +1023,16 @@ async function getTransactionDetails(txnHash) {
|
|
|
1008
1023
|
* @function signSendCoinTransaction
|
|
1009
1024
|
* @param {Wallet} wallet - A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees.
|
|
1010
1025
|
* @param {string} toAddress - The address to which the coins should be sent.
|
|
1011
|
-
* @param {string}
|
|
1026
|
+
* @param {string} coins - The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
|
|
1012
1027
|
* @param {number} nonce - The nonce of the account retrieved by invoking the getAccountDetails function. You have to carefully manage state of the nonce to avoid sending the coins multiple times, such as when retrying sendCoins after a network error.
|
|
1013
1028
|
* @return {SignResult} Returns a promise of type SignResult.
|
|
1014
1029
|
*/
|
|
1015
|
-
async function signSendCoinTransaction(wallet, toAddress,
|
|
1030
|
+
async function signSendCoinTransaction(wallet, toAddress, coins) {
|
|
1016
1031
|
if (isInitialized === false) {
|
|
1017
1032
|
return -1000;
|
|
1018
1033
|
}
|
|
1019
1034
|
|
|
1020
|
-
if (wallet == null || toAddress == null ||
|
|
1035
|
+
if (wallet == null || toAddress == null || coins == null || nonce == null) {
|
|
1021
1036
|
return new SignResult(-500, null, null);
|
|
1022
1037
|
}
|
|
1023
1038
|
|
|
@@ -1029,7 +1044,7 @@ async function signSendCoinTransaction(wallet, toAddress, coinsInWei) {
|
|
|
1029
1044
|
return new SignResult(-502, null, null);
|
|
1030
1045
|
}
|
|
1031
1046
|
|
|
1032
|
-
if (isLargeNumber(
|
|
1047
|
+
if (isLargeNumber(coins) == false) {
|
|
1033
1048
|
return new SignResult(-503, null, null);
|
|
1034
1049
|
}
|
|
1035
1050
|
|
|
@@ -1044,7 +1059,7 @@ async function signSendCoinTransaction(wallet, toAddress, coinsInWei) {
|
|
|
1044
1059
|
|
|
1045
1060
|
const contractData = null;
|
|
1046
1061
|
|
|
1047
|
-
var txSigningHash = transactionGetSigningHash(wallet.address, nonce, toAddress,
|
|
1062
|
+
var txSigningHash = transactionGetSigningHash(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData)
|
|
1048
1063
|
if (txSigningHash == null) {
|
|
1049
1064
|
return new SignResult(-506, null, null);
|
|
1050
1065
|
}
|
|
@@ -1056,12 +1071,12 @@ async function signSendCoinTransaction(wallet, toAddress, coinsInWei) {
|
|
|
1056
1071
|
return new SignResult(-507, null, null);
|
|
1057
1072
|
}
|
|
1058
1073
|
|
|
1059
|
-
var txHashHex = transactionGetTransactionHash(wallet.address, nonce, toAddress,
|
|
1074
|
+
var txHashHex = transactionGetTransactionHash(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
|
|
1060
1075
|
if (txHashHex == null) {
|
|
1061
1076
|
return new SendResult(-508, null, null);
|
|
1062
1077
|
}
|
|
1063
1078
|
|
|
1064
|
-
var txnData = transactionGetData(wallet.address, nonce, toAddress,
|
|
1079
|
+
var txnData = transactionGetData(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
|
|
1065
1080
|
if (txnData == null) {
|
|
1066
1081
|
return new SendResult(-509, null, null);
|
|
1067
1082
|
}
|
|
@@ -1078,16 +1093,16 @@ async function signSendCoinTransaction(wallet, toAddress, coinsInWei) {
|
|
|
1078
1093
|
* @function sendCoins
|
|
1079
1094
|
* @param {Wallet} wallet - A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees.
|
|
1080
1095
|
* @param {string} toAddress - The address to which the coins should be sent.
|
|
1081
|
-
* @param {string}
|
|
1096
|
+
* @param {string} coins - The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
|
|
1082
1097
|
* @param {number} nonce - The nonce of the account retrieved by invoking the getAccountDetails function. You have to carefully manage state of the nonce to avoid sending the coins multiple times, such as when retrying sendCoins after a network error.
|
|
1083
1098
|
* @return {Promise<SendResult>} Returns a promise of type SendResult.
|
|
1084
1099
|
*/
|
|
1085
|
-
async function sendCoins(wallet, toAddress,
|
|
1100
|
+
async function sendCoins(wallet, toAddress, coins, nonce) {
|
|
1086
1101
|
if (isInitialized === false) {
|
|
1087
1102
|
return -1000;
|
|
1088
1103
|
}
|
|
1089
1104
|
|
|
1090
|
-
if (wallet == null || toAddress == null ||
|
|
1105
|
+
if (wallet == null || toAddress == null || coins == null || nonce == null) {
|
|
1091
1106
|
return new SendResult(-1, null, null);
|
|
1092
1107
|
}
|
|
1093
1108
|
|
|
@@ -1099,7 +1114,7 @@ async function sendCoins(wallet, toAddress, coinsInWei, nonce) {
|
|
|
1099
1114
|
return new SendResult(-3, null, null);
|
|
1100
1115
|
}
|
|
1101
1116
|
|
|
1102
|
-
if (isLargeNumber(
|
|
1117
|
+
if (isLargeNumber(coins) == false) {
|
|
1103
1118
|
return new SendResult(-4, null, null);
|
|
1104
1119
|
}
|
|
1105
1120
|
|
|
@@ -1123,7 +1138,7 @@ async function sendCoins(wallet, toAddress, coinsInWei, nonce) {
|
|
|
1123
1138
|
|
|
1124
1139
|
const contractData = null;
|
|
1125
1140
|
|
|
1126
|
-
var txSigningHash = transactionGetSigningHash(wallet.address, nonce, toAddress,
|
|
1141
|
+
var txSigningHash = transactionGetSigningHash(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData)
|
|
1127
1142
|
if (txSigningHash == null) {
|
|
1128
1143
|
return new SendResult(-9, null, null);
|
|
1129
1144
|
}
|
|
@@ -1135,12 +1150,12 @@ async function sendCoins(wallet, toAddress, coinsInWei, nonce) {
|
|
|
1135
1150
|
return new SendResult(-10, null, null);
|
|
1136
1151
|
}
|
|
1137
1152
|
|
|
1138
|
-
var txHashHex = transactionGetTransactionHash(wallet.address, nonce, toAddress,
|
|
1153
|
+
var txHashHex = transactionGetTransactionHash(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
|
|
1139
1154
|
if (txHashHex == null) {
|
|
1140
1155
|
return new SendResult(-11, null, null);
|
|
1141
1156
|
}
|
|
1142
1157
|
|
|
1143
|
-
var txnData = transactionGetData(wallet.address, nonce, toAddress,
|
|
1158
|
+
var txnData = transactionGetData(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
|
|
1144
1159
|
if (txnData == null) {
|
|
1145
1160
|
return new SendResult(-12, null, null);
|
|
1146
1161
|
}
|
|
@@ -1175,4 +1190,3 @@ module.exports = {
|
|
|
1175
1190
|
TransactionDetails,
|
|
1176
1191
|
TransactionDetailsResult,
|
|
1177
1192
|
};
|
|
1178
|
-
|