quantumcoin 7.0.2 → 7.0.4

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.
Files changed (155) hide show
  1. package/.github/workflows/publish-npmjs.yaml +22 -22
  2. package/.gitignore +15 -15
  3. package/LICENSE +21 -21
  4. package/README-SDK.md +756 -756
  5. package/README.md +165 -152
  6. package/SPEC.md +3845 -3845
  7. package/config.d.ts +50 -50
  8. package/config.js +115 -115
  9. package/examples/AllSolidityTypes.sol +184 -184
  10. package/examples/SimpleIERC20.sol +74 -74
  11. package/examples/events.js +41 -35
  12. package/examples/events.ts +35 -0
  13. package/examples/example-generator-sdk-js.js +100 -95
  14. package/examples/example-generator-sdk-js.ts +77 -0
  15. package/examples/example-generator-sdk-ts.js +100 -95
  16. package/examples/example-generator-sdk-ts.ts +77 -0
  17. package/examples/example.js +72 -61
  18. package/examples/example.ts +61 -0
  19. package/examples/offline-signing.js +79 -0
  20. package/examples/offline-signing.ts +66 -0
  21. package/examples/package-lock.json +48 -57
  22. package/examples/package.json +32 -16
  23. package/examples/read-operations.js +32 -27
  24. package/examples/read-operations.ts +31 -0
  25. package/examples/sdk-generator-erc20.inline.json +251 -251
  26. package/examples/solidity-types.ts +43 -43
  27. package/examples/wallet-offline.js +35 -29
  28. package/examples/wallet-offline.ts +34 -0
  29. package/generate-sdk.js +1824 -1383
  30. package/index.js +12 -12
  31. package/package.json +95 -75
  32. package/scripts/copy-declarations.js +31 -0
  33. package/scripts/run-all-one-by-one.js +151 -0
  34. package/src/abi/fragments.d.ts +42 -42
  35. package/src/abi/fragments.js +63 -63
  36. package/src/abi/index.d.ts +13 -13
  37. package/src/abi/index.js +9 -9
  38. package/src/abi/interface.d.ts +128 -132
  39. package/src/abi/interface.js +590 -590
  40. package/src/abi/js-abi-coder.d.ts +8 -0
  41. package/src/abi/js-abi-coder.js +474 -474
  42. package/src/constants.d.ts +66 -61
  43. package/src/constants.js +101 -94
  44. package/src/contract/contract-factory.d.ts +28 -28
  45. package/src/contract/contract-factory.js +105 -105
  46. package/src/contract/contract.d.ts +113 -105
  47. package/src/contract/contract.js +354 -312
  48. package/src/contract/index.d.ts +9 -9
  49. package/src/contract/index.js +9 -9
  50. package/src/errors/index.d.ts +92 -92
  51. package/src/errors/index.js +188 -188
  52. package/src/generator/index.d.ts +74 -0
  53. package/src/generator/index.js +1404 -1201
  54. package/src/index.d.ts +125 -127
  55. package/src/index.js +41 -41
  56. package/src/internal/hex.d.ts +61 -61
  57. package/src/internal/hex.js +144 -144
  58. package/src/providers/extra-providers.d.ts +139 -128
  59. package/src/providers/extra-providers.js +600 -575
  60. package/src/providers/index.d.ts +17 -16
  61. package/src/providers/index.js +10 -10
  62. package/src/providers/json-rpc-provider.d.ts +12 -12
  63. package/src/providers/json-rpc-provider.js +79 -79
  64. package/src/providers/provider.d.ts +207 -196
  65. package/src/providers/provider.js +392 -359
  66. package/src/types/index.d.ts +214 -462
  67. package/src/types/index.js +9 -9
  68. package/src/utils/address.d.ts +72 -72
  69. package/src/utils/address.js +181 -182
  70. package/src/utils/encoding.d.ts +120 -120
  71. package/src/utils/encoding.js +306 -306
  72. package/src/utils/hashing.d.ts +82 -76
  73. package/src/utils/hashing.js +313 -298
  74. package/src/utils/index.d.ts +65 -55
  75. package/src/utils/index.js +13 -13
  76. package/src/utils/result.d.ts +57 -57
  77. package/src/utils/result.js +128 -128
  78. package/src/utils/rlp.d.ts +12 -12
  79. package/src/utils/rlp.js +200 -200
  80. package/src/utils/units.d.ts +29 -29
  81. package/src/utils/units.js +107 -107
  82. package/src/wallet/index.d.ts +10 -10
  83. package/src/wallet/index.js +8 -8
  84. package/src/wallet/wallet.d.ts +160 -160
  85. package/src/wallet/wallet.js +483 -489
  86. package/test/e2e/all-solidity-types.dynamic.test.js +207 -200
  87. package/test/e2e/all-solidity-types.dynamic.test.ts +191 -0
  88. package/test/e2e/all-solidity-types.fixtures.js +231 -231
  89. package/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +387 -361
  90. package/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +350 -0
  91. package/test/e2e/helpers.js +59 -47
  92. package/test/e2e/signing-context-and-fee.e2e.test.js +137 -0
  93. package/test/e2e/signing-context-and-fee.e2e.test.ts +128 -0
  94. package/test/e2e/simple-erc20.generated-sdks.e2e.test.js +168 -144
  95. package/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +141 -0
  96. package/test/e2e/transactional.test.js +245 -191
  97. package/test/e2e/transactional.test.ts +208 -0
  98. package/test/e2e/typed-generator.e2e.test.js +407 -402
  99. package/test/e2e/typed-generator.e2e.test.ts +337 -0
  100. package/test/fixtures/ConstructorParam.sol +23 -23
  101. package/test/fixtures/MultiContracts.sol +37 -37
  102. package/test/fixtures/SimpleStorage.sol +18 -18
  103. package/test/fixtures/StakingContract.abi.json +1 -1
  104. package/test/integration/ipc-provider.test.js +49 -44
  105. package/test/integration/ipc-provider.test.ts +44 -0
  106. package/test/integration/provider.test.js +88 -72
  107. package/test/integration/provider.test.ts +85 -0
  108. package/test/integration/ws-provider.test.js +41 -33
  109. package/test/integration/ws-provider.test.ts +38 -0
  110. package/test/security/malformed-input.test.js +37 -31
  111. package/test/security/malformed-input.test.ts +35 -0
  112. package/test/unit/_encrypted-output.txt +6 -0
  113. package/test/unit/_log-encrypted-jsons.js +45 -0
  114. package/test/unit/_write-keystore-fixture.js +16 -0
  115. package/test/unit/abi-interface.test.js +103 -98
  116. package/test/unit/abi-interface.test.ts +102 -0
  117. package/test/unit/address-wallet.test.js +355 -257
  118. package/test/unit/address-wallet.test.ts +342 -0
  119. package/test/unit/browser-provider.test.js +85 -82
  120. package/test/unit/browser-provider.test.ts +79 -0
  121. package/test/unit/contract.test.js +85 -82
  122. package/test/unit/contract.test.ts +83 -0
  123. package/test/unit/encoding-units-rlp.test.js +92 -89
  124. package/test/unit/encoding-units-rlp.test.ts +91 -0
  125. package/test/unit/errors.test.js +77 -74
  126. package/test/unit/errors.test.ts +76 -0
  127. package/test/unit/filter-by-blockhash.test.js +55 -52
  128. package/test/unit/filter-by-blockhash.test.ts +54 -0
  129. package/test/unit/fixtures/encrypted-keystores-48-32-36.js +9 -0
  130. package/test/unit/generate-contract-cli.test.js +42 -39
  131. package/test/unit/generate-contract-cli.test.ts +41 -0
  132. package/test/unit/generate-sdk-artifacts-json.test.js +113 -110
  133. package/test/unit/generate-sdk-artifacts-json.test.ts +110 -0
  134. package/test/unit/generator.test.js +102 -98
  135. package/test/unit/generator.test.ts +101 -0
  136. package/test/unit/hashing.test.js +68 -54
  137. package/test/unit/hashing.test.ts +67 -0
  138. package/test/unit/init.test.js +39 -36
  139. package/test/unit/init.test.ts +38 -0
  140. package/test/unit/interface.test.js +56 -53
  141. package/test/unit/interface.test.ts +54 -0
  142. package/test/unit/internal-hex.test.js +50 -47
  143. package/test/unit/internal-hex.test.ts +49 -0
  144. package/test/unit/populate-transaction.test.js +65 -0
  145. package/test/unit/populate-transaction.test.ts +64 -0
  146. package/test/unit/providers.test.js +200 -144
  147. package/test/unit/providers.test.ts +196 -0
  148. package/test/unit/result.test.js +80 -77
  149. package/test/unit/result.test.ts +79 -0
  150. package/test/unit/solidity-types.test.js +49 -46
  151. package/test/unit/solidity-types.test.ts +39 -0
  152. package/test/unit/utils.test.js +57 -54
  153. package/test/unit/utils.test.ts +56 -0
  154. package/test/verbose-logger.js +74 -0
  155. package/tsconfig.build.json +14 -0
@@ -1,95 +1,100 @@
1
- /**
2
- * SDK Generator example (JavaScript output)
3
- *
4
- * What this does:
5
- * - Compiles `SimpleIERC20.sol` with solc at `c:\solc\solc.exe`
6
- * - Writes `sdk-generator-erc20.inline.json` containing inline ABI+BIN
7
- * - Runs the repo's `generate-sdk.js` using `--artifacts-json --lang js`
8
- * - Generates a full typed package scaffold into `examples/example-generated-sdk-js`
9
- *
10
- * Usage (from repo root):
11
- * node examples/example-generator-sdk-js.js
12
- */
13
-
14
- const fs = require("node:fs");
15
- const path = require("node:path");
16
- const { execFileSync, spawnSync } = require("node:child_process");
17
-
18
- function compileSimpleErc20({ solcPath, solPath }) {
19
- const out = execFileSync(solcPath, ["--optimize", "--combined-json", "abi,bin", solPath], { encoding: "utf8" });
20
- const parsed = JSON.parse(out);
21
-
22
- const key = Object.keys(parsed.contracts || {}).find((k) => k.endsWith(":SimpleERC20"));
23
- if (!key) {
24
- throw new Error(`SimpleERC20 not found in solc output. Contracts: ${Object.keys(parsed.contracts || {}).join(", ")}`);
25
- }
26
- const c = parsed.contracts[key];
27
- const abi = JSON.parse(c.abi);
28
- const bin = String(c.bin || "");
29
- if (!bin) throw new Error("solc produced empty bytecode for SimpleERC20");
30
- const bytecode = bin.startsWith("0x") ? bin : `0x${bin}`;
31
-
32
- return { name: "SimpleERC20", abi, bin: bytecode };
33
- }
34
-
35
- function main() {
36
- const repoRoot = path.resolve(__dirname, "..");
37
- const solcPath = "c:\\solc\\solc.exe";
38
-
39
- if (!fs.existsSync(solcPath)) {
40
- throw new Error(`solc not found at ${solcPath}. Install solc there or update examples/example-generator-sdk-js.js.`);
41
- }
42
-
43
- const solPath = path.join(__dirname, "SimpleIERC20.sol");
44
- const artifactsJsonPath = path.join(__dirname, "sdk-generator-erc20.inline.json");
45
-
46
- // 1) Compile and write inline artifacts JSON (ABI array + BIN string).
47
- const artifact = compileSimpleErc20({ solcPath, solPath });
48
- fs.writeFileSync(artifactsJsonPath, JSON.stringify([artifact], null, 2) + "\n", "utf8");
49
-
50
- // 2) Generate a new package into examples/example-generated-sdk-js (delete old one first).
51
- const pkgDir = __dirname;
52
- const pkgName = "example-generated-sdk-js";
53
- const pkgRoot = path.join(pkgDir, pkgName);
54
- if (fs.existsSync(pkgRoot)) {
55
- fs.rmSync(pkgRoot, { recursive: true, force: true });
56
- }
57
-
58
- const generatorCli = path.join(repoRoot, "generate-sdk.js");
59
- const res = spawnSync(
60
- process.execPath,
61
- [
62
- generatorCli,
63
- "--lang",
64
- "js",
65
- "--artifacts-json",
66
- artifactsJsonPath,
67
- "--create-package",
68
- "--package-dir",
69
- pkgDir,
70
- "--package-name",
71
- pkgName,
72
- "--package-description",
73
- "Example generated package (JS output) for quantumcoin-sdk-generator",
74
- "--package-author",
75
- "QuantumCoin Community",
76
- "--package-license",
77
- "MIT",
78
- "--package-version",
79
- "0.0.1",
80
- "--non-interactive",
81
- ],
82
- { cwd: repoRoot, stdio: "inherit", shell: false, windowsHide: true },
83
- );
84
-
85
- if (res.error) throw res.error;
86
- if (res.status !== 0) {
87
- throw new Error(`Generator failed with exit code ${res.status}`);
88
- }
89
-
90
- // eslint-disable-next-line no-console
91
- console.log(`\nGenerated JS package at: ${pkgRoot}\n`);
92
- }
93
-
94
- main();
95
-
1
+ /**
2
+ * SDK Generator example (JavaScript output)
3
+ * Run with VERBOSE=1 for step-by-step logging.
4
+ *
5
+ * What this does:
6
+ * - Compiles `SimpleIERC20.sol` with solc (path from QC_SOLC_PATH or SOLC_PATH env, else c:\solc\solc.exe)
7
+ * - Writes `sdk-generator-erc20.inline.json` containing inline ABI+BIN
8
+ * - Runs the repo's `generate-sdk.js` using `--artifacts-json --lang js`
9
+ * - Generates a full typed package scaffold into `examples/example-generated-sdk-js`
10
+ *
11
+ * Usage (from repo root):
12
+ * node examples/example-generator-sdk-js.js
13
+ */
14
+
15
+ const fs = require("node:fs");
16
+ const path = require("node:path");
17
+ const { execFileSync, spawnSync } = require("node:child_process");
18
+ const { logExample } = require("../test/verbose-logger");
19
+
20
+ function compileSimpleErc20({ solcPath, solPath }) {
21
+ const out = execFileSync(solcPath, ["--optimize", "--combined-json", "abi,bin", solPath], { encoding: "utf8" });
22
+ const parsed = JSON.parse(out);
23
+
24
+ const key = Object.keys(parsed.contracts || {}).find((k) => k.endsWith(":SimpleERC20"));
25
+ if (!key) {
26
+ throw new Error(`SimpleERC20 not found in solc output. Contracts: ${Object.keys(parsed.contracts || {}).join(", ")}`);
27
+ }
28
+ const c = parsed.contracts[key];
29
+ const abi = JSON.parse(c.abi);
30
+ const bin = String(c.bin || "");
31
+ if (!bin) throw new Error("solc produced empty bytecode for SimpleERC20");
32
+ const bytecode = bin.startsWith("0x") ? bin : `0x${bin}`;
33
+
34
+ return { name: "SimpleERC20", abi, bin: bytecode };
35
+ }
36
+
37
+ function main() {
38
+ const solcPath = process.env.QC_SOLC_PATH || process.env.SOLC_PATH || "c:\\solc\\solc.exe";
39
+ logExample("example-generator-sdk-js.js", "starting", { solcPath });
40
+ const repoRoot = path.resolve(__dirname, "..");
41
+
42
+ if (!fs.existsSync(solcPath)) {
43
+ throw new Error(`solc not found at ${solcPath}. Set QC_SOLC_PATH or SOLC_PATH to your solc executable, or install solc at the default path.`);
44
+ }
45
+
46
+ const solPath = path.join(__dirname, "SimpleIERC20.sol");
47
+ const artifactsJsonPath = path.join(__dirname, "sdk-generator-erc20.inline.json");
48
+
49
+ // 1) Compile and write inline artifacts JSON (ABI array + BIN string).
50
+ const artifact = compileSimpleErc20({ solcPath, solPath });
51
+ logExample("example-generator-sdk-js.js", "compile SimpleERC20", { contractName: artifact.name });
52
+ fs.writeFileSync(artifactsJsonPath, JSON.stringify([artifact], null, 2) + "\n", "utf8");
53
+
54
+ // 2) Generate a new package into examples/example-generated-sdk-js (delete old one first).
55
+ const pkgDir = __dirname;
56
+ const pkgName = "example-generated-sdk-js";
57
+ const pkgRoot = path.join(pkgDir, pkgName);
58
+ if (fs.existsSync(pkgRoot)) {
59
+ fs.rmSync(pkgRoot, { recursive: true, force: true });
60
+ }
61
+ logExample("example-generator-sdk-js.js", "generate package", { pkgName, pkgRoot });
62
+
63
+ const generatorCli = path.join(repoRoot, "generate-sdk.js");
64
+ const res = spawnSync(
65
+ process.execPath,
66
+ [
67
+ generatorCli,
68
+ "--lang",
69
+ "js",
70
+ "--artifacts-json",
71
+ artifactsJsonPath,
72
+ "--create-package",
73
+ "--package-dir",
74
+ pkgDir,
75
+ "--package-name",
76
+ pkgName,
77
+ "--package-description",
78
+ "Example generated package (JS output) for sdkgen",
79
+ "--package-author",
80
+ "QuantumCoin Community",
81
+ "--package-license",
82
+ "MIT",
83
+ "--package-version",
84
+ "0.0.1",
85
+ "--non-interactive",
86
+ ],
87
+ { cwd: repoRoot, stdio: "inherit", shell: false, windowsHide: true },
88
+ );
89
+
90
+ if (res.error) throw res.error;
91
+ if (res.status !== 0) {
92
+ throw new Error(`Generator failed with exit code ${res.status}`);
93
+ }
94
+
95
+ // eslint-disable-next-line no-console
96
+ console.log(`\nGenerated JS package at: ${pkgRoot}\n`);
97
+ }
98
+
99
+ main();
100
+
@@ -0,0 +1,77 @@
1
+ /**
2
+ * SDK Generator example (JavaScript output) - TypeScript.
3
+ * Run: npx tsx examples/example-generator-sdk-js.ts
4
+ * Compiles SimpleIERC20.sol, writes sdk-generator-erc20.inline.json, runs generate-sdk.js --lang js.
5
+ */
6
+
7
+ import fs from "node:fs";
8
+ import path from "node:path";
9
+ import { execFileSync, spawnSync } from "node:child_process";
10
+ import { logExample } from "../test/verbose-logger";
11
+
12
+ function compileSimpleErc20({ solcPath, solPath }: { solcPath: string; solPath: string }) {
13
+ const out = execFileSync(solcPath, ["--optimize", "--combined-json", "abi,bin", solPath], { encoding: "utf8" });
14
+ const parsed = JSON.parse(out);
15
+ const key = Object.keys(parsed.contracts || {}).find((k) => k.endsWith(":SimpleERC20"));
16
+ if (!key) {
17
+ throw new Error(`SimpleERC20 not found in solc output. Contracts: ${Object.keys(parsed.contracts || {}).join(", ")}`);
18
+ }
19
+ const c = parsed.contracts[key];
20
+ const abi = JSON.parse(c.abi);
21
+ const bin = String(c.bin || "");
22
+ if (!bin) throw new Error("solc produced empty bytecode for SimpleERC20");
23
+ const bytecode = bin.startsWith("0x") ? bin : `0x${bin}`;
24
+ return { name: "SimpleERC20", abi, bin: bytecode };
25
+ }
26
+
27
+ function main(): void {
28
+ const solcPath = process.env.QC_SOLC_PATH || process.env.SOLC_PATH || "c:\\solc\\solc.exe";
29
+ logExample("example-generator-sdk-js.ts", "starting", { solcPath });
30
+ const repoRoot = path.resolve(__dirname, "..");
31
+
32
+ if (!fs.existsSync(solcPath)) {
33
+ throw new Error(`solc not found at ${solcPath}. Set QC_SOLC_PATH or SOLC_PATH.`);
34
+ }
35
+
36
+ const solPath = path.join(__dirname, "SimpleIERC20.sol");
37
+ const artifactsJsonPath = path.join(__dirname, "sdk-generator-erc20.inline.json");
38
+
39
+ const artifact = compileSimpleErc20({ solcPath, solPath });
40
+ logExample("example-generator-sdk-js.ts", "compile SimpleERC20", { contractName: artifact.name });
41
+ fs.writeFileSync(artifactsJsonPath, JSON.stringify([artifact], null, 2) + "\n", "utf8");
42
+
43
+ const pkgDir = __dirname;
44
+ const pkgName = "example-generated-sdk-js";
45
+ const pkgRoot = path.join(pkgDir, pkgName);
46
+ if (fs.existsSync(pkgRoot)) {
47
+ fs.rmSync(pkgRoot, { recursive: true, force: true });
48
+ }
49
+ logExample("example-generator-sdk-js.ts", "generate package", { pkgName, pkgRoot });
50
+
51
+ const generatorCli = path.join(repoRoot, "generate-sdk.js");
52
+ const res = spawnSync(
53
+ process.execPath,
54
+ [
55
+ generatorCli,
56
+ "--lang", "js",
57
+ "--artifacts-json", artifactsJsonPath,
58
+ "--create-package",
59
+ "--package-dir", pkgDir,
60
+ "--package-name", pkgName,
61
+ "--package-description", "Example generated package (JS output) for sdkgen",
62
+ "--package-author", "QuantumCoin Community",
63
+ "--package-license", "MIT",
64
+ "--package-version", "0.0.1",
65
+ "--non-interactive",
66
+ ],
67
+ { cwd: repoRoot, stdio: "inherit", shell: false, windowsHide: true },
68
+ );
69
+
70
+ if (res.error) throw res.error;
71
+ if (res.status !== 0) {
72
+ throw new Error(`Generator failed with exit code ${res.status}`);
73
+ }
74
+ console.log(`\nGenerated JS package at: ${pkgRoot}\n`);
75
+ }
76
+
77
+ main();
@@ -1,95 +1,100 @@
1
- /**
2
- * SDK Generator example (TypeScript output)
3
- *
4
- * What this does:
5
- * - Compiles `SimpleIERC20.sol` with solc at `c:\solc\solc.exe`
6
- * - Writes `sdk-generator-erc20.inline.json` containing inline ABI+BIN
7
- * - Runs the repo's `generate-sdk.js` using `--artifacts-json --lang ts`
8
- * - Generates a full typed package scaffold into `examples/example-generated-sdk-ts`
9
- *
10
- * Usage (from repo root):
11
- * node examples/example-generator-sdk-ts.js
12
- */
13
-
14
- const fs = require("node:fs");
15
- const path = require("node:path");
16
- const { execFileSync, spawnSync } = require("node:child_process");
17
-
18
- function compileSimpleErc20({ solcPath, solPath }) {
19
- const out = execFileSync(solcPath, ["--optimize", "--combined-json", "abi,bin", solPath], { encoding: "utf8" });
20
- const parsed = JSON.parse(out);
21
-
22
- const key = Object.keys(parsed.contracts || {}).find((k) => k.endsWith(":SimpleERC20"));
23
- if (!key) {
24
- throw new Error(`SimpleERC20 not found in solc output. Contracts: ${Object.keys(parsed.contracts || {}).join(", ")}`);
25
- }
26
- const c = parsed.contracts[key];
27
- const abi = JSON.parse(c.abi);
28
- const bin = String(c.bin || "");
29
- if (!bin) throw new Error("solc produced empty bytecode for SimpleERC20");
30
- const bytecode = bin.startsWith("0x") ? bin : `0x${bin}`;
31
-
32
- return { name: "SimpleERC20", abi, bin: bytecode };
33
- }
34
-
35
- function main() {
36
- const repoRoot = path.resolve(__dirname, "..");
37
- const solcPath = "c:\\solc\\solc.exe";
38
-
39
- if (!fs.existsSync(solcPath)) {
40
- throw new Error(`solc not found at ${solcPath}. Install solc there or update examples/example-generator-sdk-ts.js.`);
41
- }
42
-
43
- const solPath = path.join(__dirname, "SimpleIERC20.sol");
44
- const artifactsJsonPath = path.join(__dirname, "sdk-generator-erc20.inline.json");
45
-
46
- // 1) Compile and write inline artifacts JSON (ABI array + BIN string).
47
- const artifact = compileSimpleErc20({ solcPath, solPath });
48
- fs.writeFileSync(artifactsJsonPath, JSON.stringify([artifact], null, 2) + "\n", "utf8");
49
-
50
- // 2) Generate a new package into examples/example-generated-sdk-ts (delete old one first).
51
- const pkgDir = __dirname;
52
- const pkgName = "example-generated-sdk-ts";
53
- const pkgRoot = path.join(pkgDir, pkgName);
54
- if (fs.existsSync(pkgRoot)) {
55
- fs.rmSync(pkgRoot, { recursive: true, force: true });
56
- }
57
-
58
- const generatorCli = path.join(repoRoot, "generate-sdk.js");
59
- const res = spawnSync(
60
- process.execPath,
61
- [
62
- generatorCli,
63
- "--lang",
64
- "ts",
65
- "--artifacts-json",
66
- artifactsJsonPath,
67
- "--create-package",
68
- "--package-dir",
69
- pkgDir,
70
- "--package-name",
71
- pkgName,
72
- "--package-description",
73
- "Example generated package (TS output) for quantumcoin-sdk-generator",
74
- "--package-author",
75
- "QuantumCoin Community",
76
- "--package-license",
77
- "MIT",
78
- "--package-version",
79
- "0.0.1",
80
- "--non-interactive",
81
- ],
82
- { cwd: repoRoot, stdio: "inherit", shell: false, windowsHide: true },
83
- );
84
-
85
- if (res.error) throw res.error;
86
- if (res.status !== 0) {
87
- throw new Error(`Generator failed with exit code ${res.status}`);
88
- }
89
-
90
- // eslint-disable-next-line no-console
91
- console.log(`\nGenerated TS package at: ${pkgRoot}\n`);
92
- }
93
-
94
- main();
95
-
1
+ /**
2
+ * SDK Generator example (TypeScript output)
3
+ * Run with VERBOSE=1 for step-by-step logging.
4
+ *
5
+ * What this does:
6
+ * - Compiles `SimpleIERC20.sol` with solc (path from QC_SOLC_PATH or SOLC_PATH env, else c:\solc\solc.exe)
7
+ * - Writes `sdk-generator-erc20.inline.json` containing inline ABI+BIN
8
+ * - Runs the repo's `generate-sdk.js` using `--artifacts-json --lang ts`
9
+ * - Generates a full typed package scaffold into `examples/example-generated-sdk-ts`
10
+ *
11
+ * Usage (from repo root):
12
+ * node examples/example-generator-sdk-ts.js
13
+ */
14
+
15
+ const fs = require("node:fs");
16
+ const path = require("node:path");
17
+ const { execFileSync, spawnSync } = require("node:child_process");
18
+ const { logExample } = require("../test/verbose-logger");
19
+
20
+ function compileSimpleErc20({ solcPath, solPath }) {
21
+ const out = execFileSync(solcPath, ["--optimize", "--combined-json", "abi,bin", solPath], { encoding: "utf8" });
22
+ const parsed = JSON.parse(out);
23
+
24
+ const key = Object.keys(parsed.contracts || {}).find((k) => k.endsWith(":SimpleERC20"));
25
+ if (!key) {
26
+ throw new Error(`SimpleERC20 not found in solc output. Contracts: ${Object.keys(parsed.contracts || {}).join(", ")}`);
27
+ }
28
+ const c = parsed.contracts[key];
29
+ const abi = JSON.parse(c.abi);
30
+ const bin = String(c.bin || "");
31
+ if (!bin) throw new Error("solc produced empty bytecode for SimpleERC20");
32
+ const bytecode = bin.startsWith("0x") ? bin : `0x${bin}`;
33
+
34
+ return { name: "SimpleERC20", abi, bin: bytecode };
35
+ }
36
+
37
+ function main() {
38
+ const solcPath = process.env.QC_SOLC_PATH || process.env.SOLC_PATH || "c:\\solc\\solc.exe";
39
+ logExample("example-generator-sdk-ts.js", "starting", { solcPath });
40
+ const repoRoot = path.resolve(__dirname, "..");
41
+
42
+ if (!fs.existsSync(solcPath)) {
43
+ throw new Error(`solc not found at ${solcPath}. Set QC_SOLC_PATH or SOLC_PATH to your solc executable, or install solc at the default path.`);
44
+ }
45
+
46
+ const solPath = path.join(__dirname, "SimpleIERC20.sol");
47
+ const artifactsJsonPath = path.join(__dirname, "sdk-generator-erc20.inline.json");
48
+
49
+ // 1) Compile and write inline artifacts JSON (ABI array + BIN string).
50
+ const artifact = compileSimpleErc20({ solcPath, solPath });
51
+ logExample("example-generator-sdk-ts.js", "compile SimpleERC20", { contractName: artifact.name });
52
+ fs.writeFileSync(artifactsJsonPath, JSON.stringify([artifact], null, 2) + "\n", "utf8");
53
+
54
+ // 2) Generate a new package into examples/example-generated-sdk-ts (delete old one first).
55
+ const pkgDir = __dirname;
56
+ const pkgName = "example-generated-sdk-ts";
57
+ const pkgRoot = path.join(pkgDir, pkgName);
58
+ if (fs.existsSync(pkgRoot)) {
59
+ fs.rmSync(pkgRoot, { recursive: true, force: true });
60
+ }
61
+ logExample("example-generator-sdk-ts.js", "generate package", { pkgName, pkgRoot });
62
+
63
+ const generatorCli = path.join(repoRoot, "generate-sdk.js");
64
+ const res = spawnSync(
65
+ process.execPath,
66
+ [
67
+ generatorCli,
68
+ "--lang",
69
+ "ts",
70
+ "--artifacts-json",
71
+ artifactsJsonPath,
72
+ "--create-package",
73
+ "--package-dir",
74
+ pkgDir,
75
+ "--package-name",
76
+ pkgName,
77
+ "--package-description",
78
+ "Example generated package (TS output) for sdkgen",
79
+ "--package-author",
80
+ "QuantumCoin Community",
81
+ "--package-license",
82
+ "MIT",
83
+ "--package-version",
84
+ "0.0.1",
85
+ "--non-interactive",
86
+ ],
87
+ { cwd: repoRoot, stdio: "inherit", shell: false, windowsHide: true },
88
+ );
89
+
90
+ if (res.error) throw res.error;
91
+ if (res.status !== 0) {
92
+ throw new Error(`Generator failed with exit code ${res.status}`);
93
+ }
94
+
95
+ // eslint-disable-next-line no-console
96
+ console.log(`\nGenerated TS package at: ${pkgRoot}\n`);
97
+ }
98
+
99
+ main();
100
+
@@ -0,0 +1,77 @@
1
+ /**
2
+ * SDK Generator example (TypeScript output) - TypeScript.
3
+ * Run: npx tsx examples/example-generator-sdk-ts.ts
4
+ * Compiles SimpleIERC20.sol, writes sdk-generator-erc20.inline.json, runs generate-sdk.js --lang ts.
5
+ */
6
+
7
+ import fs from "node:fs";
8
+ import path from "node:path";
9
+ import { execFileSync, spawnSync } from "node:child_process";
10
+ import { logExample } from "../test/verbose-logger";
11
+
12
+ function compileSimpleErc20({ solcPath, solPath }: { solcPath: string; solPath: string }) {
13
+ const out = execFileSync(solcPath, ["--optimize", "--combined-json", "abi,bin", solPath], { encoding: "utf8" });
14
+ const parsed = JSON.parse(out);
15
+ const key = Object.keys(parsed.contracts || {}).find((k) => k.endsWith(":SimpleERC20"));
16
+ if (!key) {
17
+ throw new Error(`SimpleERC20 not found in solc output. Contracts: ${Object.keys(parsed.contracts || {}).join(", ")}`);
18
+ }
19
+ const c = parsed.contracts[key];
20
+ const abi = JSON.parse(c.abi);
21
+ const bin = String(c.bin || "");
22
+ if (!bin) throw new Error("solc produced empty bytecode for SimpleERC20");
23
+ const bytecode = bin.startsWith("0x") ? bin : `0x${bin}`;
24
+ return { name: "SimpleERC20", abi, bin: bytecode };
25
+ }
26
+
27
+ function main(): void {
28
+ const solcPath = process.env.QC_SOLC_PATH || process.env.SOLC_PATH || "c:\\solc\\solc.exe";
29
+ logExample("example-generator-sdk-ts.ts", "starting", { solcPath });
30
+ const repoRoot = path.resolve(__dirname, "..");
31
+
32
+ if (!fs.existsSync(solcPath)) {
33
+ throw new Error(`solc not found at ${solcPath}. Set QC_SOLC_PATH or SOLC_PATH.`);
34
+ }
35
+
36
+ const solPath = path.join(__dirname, "SimpleIERC20.sol");
37
+ const artifactsJsonPath = path.join(__dirname, "sdk-generator-erc20.inline.json");
38
+
39
+ const artifact = compileSimpleErc20({ solcPath, solPath });
40
+ logExample("example-generator-sdk-ts.ts", "compile SimpleERC20", { contractName: artifact.name });
41
+ fs.writeFileSync(artifactsJsonPath, JSON.stringify([artifact], null, 2) + "\n", "utf8");
42
+
43
+ const pkgDir = __dirname;
44
+ const pkgName = "example-generated-sdk-ts";
45
+ const pkgRoot = path.join(pkgDir, pkgName);
46
+ if (fs.existsSync(pkgRoot)) {
47
+ fs.rmSync(pkgRoot, { recursive: true, force: true });
48
+ }
49
+ logExample("example-generator-sdk-ts.ts", "generate package", { pkgName, pkgRoot });
50
+
51
+ const generatorCli = path.join(repoRoot, "generate-sdk.js");
52
+ const res = spawnSync(
53
+ process.execPath,
54
+ [
55
+ generatorCli,
56
+ "--lang", "ts",
57
+ "--artifacts-json", artifactsJsonPath,
58
+ "--create-package",
59
+ "--package-dir", pkgDir,
60
+ "--package-name", pkgName,
61
+ "--package-description", "Example generated package (TS output) for sdkgen",
62
+ "--package-author", "QuantumCoin Community",
63
+ "--package-license", "MIT",
64
+ "--package-version", "0.0.1",
65
+ "--non-interactive",
66
+ ],
67
+ { cwd: repoRoot, stdio: "inherit", shell: false, windowsHide: true },
68
+ );
69
+
70
+ if (res.error) throw res.error;
71
+ if (res.status !== 0) {
72
+ throw new Error(`Generator failed with exit code ${res.status}`);
73
+ }
74
+ console.log(`\nGenerated TS package at: ${pkgRoot}\n`);
75
+ }
76
+
77
+ main();