quantum-coin-js-sdk 2.0.1 → 2.1.0

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 (232) hide show
  1. package/README.md +13 -0
  2. package/index.d.ts +9 -0
  3. package/index.js +37 -4
  4. package/package.json +12 -4
  5. package/wasmBase64.js +3 -2
  6. package/.idea/.name +0 -1
  7. package/.idea/modules.xml +0 -8
  8. package/.idea/quantum-coin-js-sdk.iml +0 -12
  9. package/.idea/vcs.xml +0 -6
  10. package/.vs/ProjectSettings.json +0 -3
  11. package/.vs/VSWorkspaceState.json +0 -8
  12. package/.vs/quantum-coin-js-sdk/FileContentIndex/a9d6de82-cfc3-4c22-ac38-06d706ff3673.vsidx +0 -0
  13. package/.vs/quantum-coin-js-sdk/FileContentIndex/fdc816df-1898-4153-99f2-c69ef4c2283b.vsidx +0 -0
  14. package/.vs/quantum-coin-js-sdk/config/applicationhost.config +0 -1011
  15. package/.vs/quantum-coin-js-sdk/v17/.wsuo +0 -0
  16. package/.vs/quantum-coin-js-sdk/v17/DocumentLayout.backup.json +0 -39
  17. package/.vs/quantum-coin-js-sdk/v17/DocumentLayout.json +0 -57
  18. package/.vs/slnx.sqlite +0 -0
  19. package/example/README.md +0 -14
  20. package/example/conversion-example.js +0 -19
  21. package/example/example-create-contract.js +0 -396
  22. package/example/example-encode-decode-rlp.js +0 -225
  23. package/example/example-event-pack-unpack.js +0 -391
  24. package/example/example-misc.js +0 -96
  25. package/example/example-token-pack-unpack.js +0 -960
  26. package/example/example-wallet-version4.js +0 -34
  27. package/example/example-wallet.js +0 -39
  28. package/example/example.js +0 -115
  29. package/example/node_modules/.bin/sdkgen +0 -16
  30. package/example/node_modules/.bin/sdkgen.cmd +0 -17
  31. package/example/node_modules/.bin/sdkgen.ps1 +0 -28
  32. package/example/node_modules/.package-lock.json +0 -51
  33. package/example/node_modules/quantumcoin/.github/workflows/publish-npmjs.yaml +0 -22
  34. package/example/node_modules/quantumcoin/LICENSE +0 -21
  35. package/example/node_modules/quantumcoin/README-SDK.md +0 -828
  36. package/example/node_modules/quantumcoin/README.md +0 -197
  37. package/example/node_modules/quantumcoin/config.d.ts +0 -50
  38. package/example/node_modules/quantumcoin/config.js +0 -123
  39. package/example/node_modules/quantumcoin/examples/AllSolidityTypes.sol +0 -184
  40. package/example/node_modules/quantumcoin/examples/SimpleIERC20.sol +0 -74
  41. package/example/node_modules/quantumcoin/examples/events.js +0 -41
  42. package/example/node_modules/quantumcoin/examples/events.ts +0 -35
  43. package/example/node_modules/quantumcoin/examples/example-generator-sdk-js.js +0 -100
  44. package/example/node_modules/quantumcoin/examples/example-generator-sdk-js.ts +0 -77
  45. package/example/node_modules/quantumcoin/examples/example-generator-sdk-ts.js +0 -100
  46. package/example/node_modules/quantumcoin/examples/example-generator-sdk-ts.ts +0 -77
  47. package/example/node_modules/quantumcoin/examples/example.js +0 -67
  48. package/example/node_modules/quantumcoin/examples/example.ts +0 -56
  49. package/example/node_modules/quantumcoin/examples/offline-signing.js +0 -77
  50. package/example/node_modules/quantumcoin/examples/offline-signing.ts +0 -65
  51. package/example/node_modules/quantumcoin/examples/package-lock.json +0 -596
  52. package/example/node_modules/quantumcoin/examples/package.json +0 -32
  53. package/example/node_modules/quantumcoin/examples/read-operations.js +0 -32
  54. package/example/node_modules/quantumcoin/examples/read-operations.ts +0 -31
  55. package/example/node_modules/quantumcoin/examples/sdk-generator-erc20.inline.json +0 -251
  56. package/example/node_modules/quantumcoin/examples/solidity-types.ts +0 -43
  57. package/example/node_modules/quantumcoin/examples/wallet-offline.js +0 -36
  58. package/example/node_modules/quantumcoin/examples/wallet-offline.ts +0 -26
  59. package/example/node_modules/quantumcoin/generate-sdk.js +0 -1846
  60. package/example/node_modules/quantumcoin/index.js +0 -12
  61. package/example/node_modules/quantumcoin/package.json +0 -95
  62. package/example/node_modules/quantumcoin/scripts/copy-declarations.js +0 -31
  63. package/example/node_modules/quantumcoin/scripts/run-all-one-by-one.js +0 -151
  64. package/example/node_modules/quantumcoin/src/abi/fragments.d.ts +0 -42
  65. package/example/node_modules/quantumcoin/src/abi/fragments.js +0 -63
  66. package/example/node_modules/quantumcoin/src/abi/index.d.ts +0 -13
  67. package/example/node_modules/quantumcoin/src/abi/index.js +0 -9
  68. package/example/node_modules/quantumcoin/src/abi/interface.d.ts +0 -128
  69. package/example/node_modules/quantumcoin/src/abi/interface.js +0 -605
  70. package/example/node_modules/quantumcoin/src/abi/js-abi-coder.d.ts +0 -8
  71. package/example/node_modules/quantumcoin/src/abi/js-abi-coder.js +0 -538
  72. package/example/node_modules/quantumcoin/src/constants.d.ts +0 -61
  73. package/example/node_modules/quantumcoin/src/constants.js +0 -94
  74. package/example/node_modules/quantumcoin/src/contract/contract-factory.d.ts +0 -28
  75. package/example/node_modules/quantumcoin/src/contract/contract-factory.js +0 -111
  76. package/example/node_modules/quantumcoin/src/contract/contract.d.ts +0 -113
  77. package/example/node_modules/quantumcoin/src/contract/contract.js +0 -408
  78. package/example/node_modules/quantumcoin/src/contract/index.d.ts +0 -9
  79. package/example/node_modules/quantumcoin/src/contract/index.js +0 -9
  80. package/example/node_modules/quantumcoin/src/errors/index.d.ts +0 -92
  81. package/example/node_modules/quantumcoin/src/errors/index.js +0 -200
  82. package/example/node_modules/quantumcoin/src/generator/index.d.ts +0 -81
  83. package/example/node_modules/quantumcoin/src/generator/index.js +0 -1571
  84. package/example/node_modules/quantumcoin/src/index.d.ts +0 -122
  85. package/example/node_modules/quantumcoin/src/index.js +0 -41
  86. package/example/node_modules/quantumcoin/src/internal/hex.d.ts +0 -68
  87. package/example/node_modules/quantumcoin/src/internal/hex.js +0 -180
  88. package/example/node_modules/quantumcoin/src/providers/extra-providers.d.ts +0 -139
  89. package/example/node_modules/quantumcoin/src/providers/extra-providers.js +0 -614
  90. package/example/node_modules/quantumcoin/src/providers/index.d.ts +0 -17
  91. package/example/node_modules/quantumcoin/src/providers/index.js +0 -10
  92. package/example/node_modules/quantumcoin/src/providers/json-rpc-provider.d.ts +0 -12
  93. package/example/node_modules/quantumcoin/src/providers/json-rpc-provider.js +0 -89
  94. package/example/node_modules/quantumcoin/src/providers/provider.d.ts +0 -206
  95. package/example/node_modules/quantumcoin/src/providers/provider.js +0 -524
  96. package/example/node_modules/quantumcoin/src/types/index.d.ts +0 -214
  97. package/example/node_modules/quantumcoin/src/types/index.js +0 -9
  98. package/example/node_modules/quantumcoin/src/utils/address.d.ts +0 -58
  99. package/example/node_modules/quantumcoin/src/utils/address.js +0 -144
  100. package/example/node_modules/quantumcoin/src/utils/encoding.d.ts +0 -120
  101. package/example/node_modules/quantumcoin/src/utils/encoding.js +0 -306
  102. package/example/node_modules/quantumcoin/src/utils/fixednumber.d.ts +0 -57
  103. package/example/node_modules/quantumcoin/src/utils/fixednumber.js +0 -366
  104. package/example/node_modules/quantumcoin/src/utils/hashing.d.ts +0 -76
  105. package/example/node_modules/quantumcoin/src/utils/hashing.js +0 -298
  106. package/example/node_modules/quantumcoin/src/utils/index.d.ts +0 -63
  107. package/example/node_modules/quantumcoin/src/utils/index.js +0 -14
  108. package/example/node_modules/quantumcoin/src/utils/result.d.ts +0 -57
  109. package/example/node_modules/quantumcoin/src/utils/result.js +0 -128
  110. package/example/node_modules/quantumcoin/src/utils/rlp.d.ts +0 -12
  111. package/example/node_modules/quantumcoin/src/utils/rlp.js +0 -215
  112. package/example/node_modules/quantumcoin/src/utils/units.d.ts +0 -29
  113. package/example/node_modules/quantumcoin/src/utils/units.js +0 -107
  114. package/example/node_modules/quantumcoin/src/wallet/index.d.ts +0 -10
  115. package/example/node_modules/quantumcoin/src/wallet/index.js +0 -8
  116. package/example/node_modules/quantumcoin/src/wallet/wallet.d.ts +0 -192
  117. package/example/node_modules/quantumcoin/src/wallet/wallet.js +0 -713
  118. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.dynamic.test.js +0 -207
  119. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.dynamic.test.ts +0 -191
  120. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.fixtures.js +0 -231
  121. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +0 -387
  122. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +0 -350
  123. package/example/node_modules/quantumcoin/test/e2e/generator-interface.e2e.test.js +0 -165
  124. package/example/node_modules/quantumcoin/test/e2e/generator-interface.e2e.test.ts +0 -160
  125. package/example/node_modules/quantumcoin/test/e2e/helpers.js +0 -59
  126. package/example/node_modules/quantumcoin/test/e2e/signing-context-and-fee.e2e.test.js +0 -141
  127. package/example/node_modules/quantumcoin/test/e2e/signing-context-and-fee.e2e.test.ts +0 -128
  128. package/example/node_modules/quantumcoin/test/e2e/simple-erc20.generated-sdks.e2e.test.js +0 -168
  129. package/example/node_modules/quantumcoin/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +0 -141
  130. package/example/node_modules/quantumcoin/test/e2e/transactional.test.js +0 -245
  131. package/example/node_modules/quantumcoin/test/e2e/transactional.test.ts +0 -208
  132. package/example/node_modules/quantumcoin/test/e2e/typed-generator.e2e.test.js +0 -407
  133. package/example/node_modules/quantumcoin/test/e2e/typed-generator.e2e.test.ts +0 -337
  134. package/example/node_modules/quantumcoin/test/fixtures/ConstructorParam.sol +0 -23
  135. package/example/node_modules/quantumcoin/test/fixtures/MultiContracts.sol +0 -37
  136. package/example/node_modules/quantumcoin/test/fixtures/SimpleStorage.sol +0 -18
  137. package/example/node_modules/quantumcoin/test/fixtures/StakingContract.abi.json +0 -1
  138. package/example/node_modules/quantumcoin/test/integration/ipc-provider.test.js +0 -49
  139. package/example/node_modules/quantumcoin/test/integration/ipc-provider.test.ts +0 -44
  140. package/example/node_modules/quantumcoin/test/integration/provider.test.js +0 -88
  141. package/example/node_modules/quantumcoin/test/integration/provider.test.ts +0 -85
  142. package/example/node_modules/quantumcoin/test/integration/ws-provider.test.js +0 -41
  143. package/example/node_modules/quantumcoin/test/integration/ws-provider.test.ts +0 -38
  144. package/example/node_modules/quantumcoin/test/security/abi-decoder-bounds.test.js +0 -122
  145. package/example/node_modules/quantumcoin/test/security/contract-overrides.test.js +0 -112
  146. package/example/node_modules/quantumcoin/test/security/generator-injection.test.js +0 -195
  147. package/example/node_modules/quantumcoin/test/security/malformed-input.test.js +0 -330
  148. package/example/node_modules/quantumcoin/test/security/malformed-input.test.ts +0 -35
  149. package/example/node_modules/quantumcoin/test/security/rpc-numeric-bounds.test.js +0 -81
  150. package/example/node_modules/quantumcoin/test/security/rpc-trust.test.js +0 -202
  151. package/example/node_modules/quantumcoin/test/unit/_encrypted-output.txt +0 -6
  152. package/example/node_modules/quantumcoin/test/unit/_log-encrypted-jsons.js +0 -45
  153. package/example/node_modules/quantumcoin/test/unit/_write-keystore-fixture.js +0 -16
  154. package/example/node_modules/quantumcoin/test/unit/abi-interface.test.js +0 -110
  155. package/example/node_modules/quantumcoin/test/unit/abi-interface.test.ts +0 -109
  156. package/example/node_modules/quantumcoin/test/unit/address-wallet.test.js +0 -923
  157. package/example/node_modules/quantumcoin/test/unit/address-wallet.test.ts +0 -877
  158. package/example/node_modules/quantumcoin/test/unit/browser-provider.test.js +0 -85
  159. package/example/node_modules/quantumcoin/test/unit/browser-provider.test.ts +0 -79
  160. package/example/node_modules/quantumcoin/test/unit/contract.test.js +0 -85
  161. package/example/node_modules/quantumcoin/test/unit/contract.test.ts +0 -83
  162. package/example/node_modules/quantumcoin/test/unit/encoding-units-rlp.test.js +0 -127
  163. package/example/node_modules/quantumcoin/test/unit/encoding-units-rlp.test.ts +0 -91
  164. package/example/node_modules/quantumcoin/test/unit/errors.test.js +0 -77
  165. package/example/node_modules/quantumcoin/test/unit/errors.test.ts +0 -76
  166. package/example/node_modules/quantumcoin/test/unit/filter-by-blockhash.test.js +0 -55
  167. package/example/node_modules/quantumcoin/test/unit/filter-by-blockhash.test.ts +0 -54
  168. package/example/node_modules/quantumcoin/test/unit/fixednumber.test.js +0 -656
  169. package/example/node_modules/quantumcoin/test/unit/fixednumber.test.ts +0 -660
  170. package/example/node_modules/quantumcoin/test/unit/fixtures/encrypted-keystores-48-32-36.js +0 -9
  171. package/example/node_modules/quantumcoin/test/unit/generate-contract-cli.test.js +0 -42
  172. package/example/node_modules/quantumcoin/test/unit/generate-contract-cli.test.ts +0 -41
  173. package/example/node_modules/quantumcoin/test/unit/generate-sdk-artifacts-json.test.js +0 -113
  174. package/example/node_modules/quantumcoin/test/unit/generate-sdk-artifacts-json.test.ts +0 -110
  175. package/example/node_modules/quantumcoin/test/unit/generator.test.js +0 -149
  176. package/example/node_modules/quantumcoin/test/unit/generator.test.ts +0 -148
  177. package/example/node_modules/quantumcoin/test/unit/hashing.test.js +0 -64
  178. package/example/node_modules/quantumcoin/test/unit/hashing.test.ts +0 -63
  179. package/example/node_modules/quantumcoin/test/unit/init.test.js +0 -39
  180. package/example/node_modules/quantumcoin/test/unit/init.test.ts +0 -38
  181. package/example/node_modules/quantumcoin/test/unit/interface.test.js +0 -56
  182. package/example/node_modules/quantumcoin/test/unit/interface.test.ts +0 -54
  183. package/example/node_modules/quantumcoin/test/unit/internal-hex.test.js +0 -81
  184. package/example/node_modules/quantumcoin/test/unit/internal-hex.test.ts +0 -80
  185. package/example/node_modules/quantumcoin/test/unit/populate-transaction.test.js +0 -98
  186. package/example/node_modules/quantumcoin/test/unit/populate-transaction.test.ts +0 -64
  187. package/example/node_modules/quantumcoin/test/unit/providers.test.js +0 -252
  188. package/example/node_modules/quantumcoin/test/unit/providers.test.ts +0 -251
  189. package/example/node_modules/quantumcoin/test/unit/result.test.js +0 -80
  190. package/example/node_modules/quantumcoin/test/unit/result.test.ts +0 -79
  191. package/example/node_modules/quantumcoin/test/unit/solidity-types.test.js +0 -49
  192. package/example/node_modules/quantumcoin/test/unit/solidity-types.test.ts +0 -39
  193. package/example/node_modules/quantumcoin/test/unit/utils.test.js +0 -57
  194. package/example/node_modules/quantumcoin/test/unit/utils.test.ts +0 -56
  195. package/example/node_modules/quantumcoin/test/verbose-logger.js +0 -74
  196. package/example/node_modules/quantumcoin/tsconfig.build.json +0 -14
  197. package/example/node_modules/seed-words/.github/workflows/publish-npmjs.yaml +0 -22
  198. package/example/node_modules/seed-words/BUILD.md +0 -7
  199. package/example/node_modules/seed-words/LICENSE +0 -121
  200. package/example/node_modules/seed-words/README.md +0 -67
  201. package/example/node_modules/seed-words/dist/seedwords.d.ts +0 -39
  202. package/example/node_modules/seed-words/package.json +0 -27
  203. package/example/node_modules/seed-words/seedwords.js +0 -315
  204. package/example/node_modules/seed-words/seedwords.txt +0 -65536
  205. package/example/node_modules/seed-words/tsconfig.json +0 -21
  206. package/example/package-lock.json +0 -60
  207. package/example/package.json +0 -15
  208. package/scripts/build-browser-tests.js +0 -29
  209. package/scripts/build-wasm.js +0 -85
  210. package/tests/browser/bundle.js +0 -97643
  211. package/tests/browser/entry.js +0 -57
  212. package/tests/browser/harness.html +0 -20
  213. package/tests/browser/run-browser.js +0 -50
  214. package/tests/encrypted-32.json +0 -1
  215. package/tests/encrypted-36.json +0 -1
  216. package/tests/encrypted-48.json +0 -1
  217. package/tests/generate-verify-vectors.js +0 -88
  218. package/tests/get-gas-price.test.js +0 -59
  219. package/tests/hashing.test.js +0 -34
  220. package/tests/non-transactional.preinit.test.js +0 -33
  221. package/tests/non-transactional.test.js +0 -1318
  222. package/tests/sign-raw-keytype5-context-null.test.js +0 -105
  223. package/tests/sign-raw-transaction.test.js +0 -194
  224. package/tests/sign-verify.test.js +0 -308
  225. package/tests/specs/assert.js +0 -74
  226. package/tests/specs/crypto.spec.js +0 -104
  227. package/tests/specs/hex.js +0 -31
  228. package/tests/specs/preinit.spec.js +0 -19
  229. package/tests/specs/sign.spec.js +0 -90
  230. package/tests/specs/wallet.spec.js +0 -98
  231. package/tests/transactional.rpc.test.js +0 -102
  232. package/tests/verify-vectors.json +0 -95035
Binary file
@@ -1,39 +0,0 @@
1
- {
2
- "Version": 1,
3
- "WorkspaceRootPath": "C:\\github\\quantum-coin-js-sdk\\",
4
- "Documents": [],
5
- "DocumentGroupContainers": [
6
- {
7
- "Orientation": 1,
8
- "VerticalTabListWidth": 256,
9
- "DocumentGroups": [
10
- {
11
- "DockedHeight": 200,
12
- "SelectedChildIndex": -1,
13
- "Children": [
14
- {
15
- "$type": "Bookmark",
16
- "Name": "ST:128:0:{13b12e3e-c1b4-4539-9371-4fe9a0d523fc}"
17
- },
18
- {
19
- "$type": "Bookmark",
20
- "Name": "ST:0:0:{34e76e81-ee4a-11d0-ae2e-00a0c90fffc3}"
21
- },
22
- {
23
- "$type": "Bookmark",
24
- "Name": "ST:131:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
25
- },
26
- {
27
- "$type": "Bookmark",
28
- "Name": "ST:130:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
29
- },
30
- {
31
- "$type": "Bookmark",
32
- "Name": "ST:129:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
33
- }
34
- ]
35
- }
36
- ]
37
- }
38
- ]
39
- }
@@ -1,57 +0,0 @@
1
- {
2
- "Version": 1,
3
- "WorkspaceRootPath": "C:\\github\\quantum-coin-js-sdk\\",
4
- "Documents": [
5
- {
6
- "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\github\\quantum-coin-js-sdk\\index.js||{14D17961-FE51-464D-9111-C4AF11D7D99A}",
7
- "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:index.js||{14D17961-FE51-464D-9111-C4AF11D7D99A}"
8
- }
9
- ],
10
- "DocumentGroupContainers": [
11
- {
12
- "Orientation": 1,
13
- "VerticalTabListWidth": 256,
14
- "DocumentGroups": [
15
- {
16
- "DockedHeight": 200,
17
- "SelectedChildIndex": 5,
18
- "Children": [
19
- {
20
- "$type": "Bookmark",
21
- "Name": "ST:128:0:{13b12e3e-c1b4-4539-9371-4fe9a0d523fc}"
22
- },
23
- {
24
- "$type": "Bookmark",
25
- "Name": "ST:0:0:{34e76e81-ee4a-11d0-ae2e-00a0c90fffc3}"
26
- },
27
- {
28
- "$type": "Bookmark",
29
- "Name": "ST:131:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
30
- },
31
- {
32
- "$type": "Bookmark",
33
- "Name": "ST:130:0:{1fc202d4-d401-403c-9834-5b218574bb67}"
34
- },
35
- {
36
- "$type": "Bookmark",
37
- "Name": "ST:129:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}"
38
- },
39
- {
40
- "$type": "Document",
41
- "DocumentIndex": 0,
42
- "Title": "index.js",
43
- "DocumentMoniker": "C:\\github\\quantum-coin-js-sdk\\index.js",
44
- "RelativeDocumentMoniker": "index.js",
45
- "ToolTip": "C:\\github\\quantum-coin-js-sdk\\index.js",
46
- "RelativeToolTip": "index.js",
47
- "ViewState": "AgIAAJAGAAAAAAAAAAAYwJwGAABKAAAAAAAAAA==",
48
- "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001646|",
49
- "WhenOpened": "2025-07-21T00:28:27.489Z",
50
- "EditorCaption": ""
51
- }
52
- ]
53
- }
54
- ]
55
- }
56
- ]
57
- }
package/.vs/slnx.sqlite DELETED
Binary file
package/example/README.md DELETED
@@ -1,14 +0,0 @@
1
- ## Quantum Coin SDK Example
2
-
3
- Example for using Quantum Coin SDK
4
-
5
- Requires Node.js version v20.18.1 or higher
6
-
7
- To run the project:
8
-
9
- npm install
10
-
11
-
12
- node example.js
13
-
14
- The example contains many async API calls, hence you might notice that the log output will be skewed.
@@ -1,19 +0,0 @@
1
- const { formatEther, parseEther } = require('quantumcoin');
2
-
3
- let hexValue = "0xDE0B6B3A7640000";
4
-
5
- //Convert hex to wei
6
- let weiValueExample = BigInt(hexValue).toString();
7
- console.log("hex to wei example: hex:" + hexValue + ", wei: " + weiValueExample);
8
-
9
- //Convert wei to eth
10
- let ethValueExample = formatEther(weiValueExample);
11
- console.log("wei to eth example: wei:" + weiValueExample + ", eth (coins): " + ethValueExample);
12
-
13
- //Convert eth to wei
14
- let weiValueExample2 = parseEther(ethValueExample);
15
- console.log("eth to wei example: eth (coins):" + ethValueExample + ", wei: " + weiValueExample2);
16
-
17
- //Convert wei to hex
18
- let hexValue2 = "0x" + BigInt(weiValueExample2).toString(16);
19
- console.log("wei to hex example : hex: " + hexValue2 + ", wei: " + weiValueExample2);
@@ -1,396 +0,0 @@
1
- const qcsdk = require('quantum-coin-js-sdk');
2
- const readline = require('readline');
3
-
4
- /**
5
- * Example: Creating a Smart Contract using signRawTransaction
6
- *
7
- * This example demonstrates how to create a smart contract on the Quantum Coin blockchain
8
- * using signRawTransaction and sendRawTransaction.
9
- *
10
- * STEPS TO COMPILE THE SOLIDITY CONTRACT:
11
- *
12
- * 1. Download the Solidity compiler (solc.exe) from:
13
- * https://github.com/quantumcoinproject/Solidity/releases/tag/v32b.8.12
14
- *
15
- * 2. Save the Solidity contract code below to a file (e.g., SimpleStorage.sol)
16
- *
17
- * 3. Compile the contract using the following command:
18
- * c:\solc\solc.exe --bin SimpleStorage.sol
19
- *
20
- * This will output the bytecode. Look for the "Binary:" section in the output.
21
- *
22
- * 4. Copy the bytecode (without the 0x prefix if present) and paste it into the
23
- * CONTRACT_BYTECODE variable below, ensuring it starts with "0x"
24
- *
25
- * Example compilation output format:
26
- * ======= SimpleStorage.sol:SimpleStorage =======
27
- * Binary:
28
- * 608060405234801561001057600080fd5b50...
29
- *
30
- * 5. Replace the CONTRACT_BYTECODE placeholder below with the actual compiled bytecode
31
- */
32
-
33
- /**
34
- * Simple Solidity Contract Example:
35
-
36
- Save this to a file named SimpleStorage.sol for compilation
37
-
38
- // SPDX-License-Identifier: MIT
39
- pragma solidity ^0.7.6;
40
-
41
- contract SimpleStorage {
42
- uint256 private storedValue;
43
-
44
- event ValueChanged(uint256 newValue);
45
-
46
- function set(uint256 value) public {
47
- storedValue = value;
48
- emit ValueChanged(value);
49
- }
50
-
51
- function get() public view returns (uint256) {
52
- return storedValue;
53
- }
54
- }
55
- */
56
-
57
- // ============================================
58
- // COMPILATION INSTRUCTIONS:
59
- // ============================================
60
- // 1. Download solc.exe from: https://github.com/quantumcoinproject/Solidity/releases/tag/v32b.8.12
61
- // 2. Save the Solidity code above to SimpleStorage.sol
62
- // 3. Run: c:\gethbuild\solc.exe --bin SimpleStorage.sol
63
- // 4. Copy the bytecode from the "Binary:" section
64
- // 5. Paste it below in CONTRACT_BYTECODE, ensuring it starts with "0x"
65
- // ============================================
66
-
67
- // Replace below placeholder CONTRACT_BYTECODE with the actual compiled bytecode from solc.exe
68
- // The bytecode should be a hex string starting with "0x"
69
- // After compiling with: c:\gethbuild\solc.exe --bin SimpleStorage.sol
70
- // Copy the bytecode from the "Binary:" section and paste it here
71
- const CONTRACT_BYTECODE = "0x608060405234801561001057600080fd5b5060fe8061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806360fe47b11460375780636d4ce63c146062575b600080fd5b606060048036036020811015604b57600080fd5b8101908080359060200190929190505050607e565b005b606860bf565b6040518082815260200191505060405180910390f35b806000819055507f93fe6d397c74fdf1402a8b72e47b68512f0510d7b98a4bc4cbdf6ac7108b3c59816040518082815260200191505060405180910390a150565b6000805490509056fea26469706673582212204638427ab77bf9babc9db8fb5d8f69323478e00367c47884b65ee0677a337f8e64736f6c63430007060033";
72
-
73
- // Configuration
74
- var clientConfigVal = new qcsdk.Config(123123); //Mainnet
75
- //Mainnet Block Explorer: https://scan.quantumcoin.org
76
-
77
- const rpcEndpointUrl = 'https://public.rpc.quantumcoinapi.com';
78
-
79
- /**
80
- * Helper function to get transaction count (nonce) from RPC
81
- */
82
- async function getTransactionCount(address) {
83
- try {
84
- const params = [address, "latest"];
85
- const response = await fetch(rpcEndpointUrl, {
86
- method: 'POST',
87
- headers: {
88
- 'Content-Type': 'application/json',
89
- },
90
- body: JSON.stringify({
91
- jsonrpc: '2.0',
92
- id: 1,
93
- method: 'eth_getTransactionCount',
94
- params: params,
95
- }),
96
- });
97
-
98
- if (!response.ok) {
99
- throw new Error(`HTTP error! status: ${response.status}`);
100
- }
101
-
102
- const result = await response.json();
103
- if (result.error) {
104
- throw new Error(result.error.message);
105
- }
106
- return parseInt(result.result, 16);
107
- } catch (error) {
108
- console.error('Could not get transaction count:', error);
109
- throw error;
110
- }
111
- }
112
-
113
- /**
114
- * Helper function to calculate gas price
115
- * QuantumCoin uses a fixed gas price: 1000 coins per 21000 gas units
116
- * Gas price = (1000 coins * 10^18 wei) / 21000 gas = wei per gas unit
117
- */
118
- function getGasPrice() {
119
- const gasPriceWei = BigInt("47619047619047600");
120
-
121
- return gasPriceWei;
122
- }
123
-
124
- /**
125
- * Helper function to prompt user for confirmation
126
- */
127
- function promptUser(question) {
128
- const rl = readline.createInterface({
129
- input: process.stdin,
130
- output: process.stdout
131
- });
132
-
133
- return new Promise((resolve) => {
134
- rl.question(question, (answer) => {
135
- rl.close();
136
- resolve(answer.toLowerCase().trim());
137
- });
138
- });
139
- }
140
-
141
- /**
142
- * Helper function to convert wei to coins
143
- */
144
- function weiToCoins(wei) {
145
- const oneCoinInWei = BigInt("1000000000000000000");
146
- const coins = Number(wei) / Number(oneCoinInWei);
147
- return coins;
148
- }
149
-
150
- /**
151
- * Helper function to estimate gas for a transaction via RPC
152
- */
153
- async function estimateGas(fromAddress, toAddress, value, data) {
154
- try {
155
- const txObject = {
156
- from: fromAddress,
157
- to: toAddress, // null for contract creation
158
- value: value,
159
- data: data
160
- };
161
-
162
- const params = [txObject, "latest"];
163
- const response = await fetch(rpcEndpointUrl, {
164
- method: 'POST',
165
- headers: {
166
- 'Content-Type': 'application/json',
167
- },
168
- body: JSON.stringify({
169
- jsonrpc: '2.0',
170
- id: 1,
171
- method: 'eth_estimateGas',
172
- params: params,
173
- }),
174
- });
175
-
176
- if (!response.ok) {
177
- throw new Error(`HTTP error! status: ${response.status}`);
178
- }
179
-
180
- const result = await response.json();
181
- if (result.error) {
182
- throw new Error(result.error.message);
183
- }
184
- return parseInt(result.result, 16);
185
- } catch (error) {
186
- console.error('Could not estimate gas:', error);
187
- throw error;
188
- }
189
- }
190
-
191
- /**
192
- * Helper function to send raw transaction via RPC
193
- */
194
- async function sendRawTransaction(signedTxData) {
195
- try {
196
- const params = [signedTxData];
197
- const response = await fetch(rpcEndpointUrl, {
198
- method: 'POST',
199
- headers: {
200
- 'Content-Type': 'application/json',
201
- },
202
- body: JSON.stringify({
203
- jsonrpc: '2.0',
204
- id: 1,
205
- method: 'eth_sendRawTransaction',
206
- params: params,
207
- }),
208
- });
209
-
210
- if (!response.ok) {
211
- throw new Error(`HTTP error! status: ${response.status}`);
212
- }
213
-
214
- const result = await response.json();
215
- if (result.error) {
216
- throw new Error(result.error.message);
217
- }
218
- return result.result; // Returns transaction hash
219
- } catch (error) {
220
- console.error('Could not send raw transaction:', error);
221
- throw error;
222
- }
223
- }
224
-
225
- //Initialize the SDK
226
- qcsdk.initialize(clientConfigVal).then(async (initResult) => {
227
- if (initResult === false) {
228
- console.error("Initialize failed");
229
- return;
230
- }
231
-
232
- console.log("=== Example: Creating a Smart Contract ===\n");
233
-
234
- // Open a wallet
235
- let examplePassphrase = "QuantumCoinExample123!";
236
- const walletEncryptedJson = "{\"address\":\"45dc00282f80628911a15775cd821a3747d2c62e14e54d1339f057c9e921be71\",\"crypto\":{\"cipher\":\"aes-256-ctr\",\"ciphertext\":\"a831e40b8e99a534df5b6dee638742f5d5ebddf07d0aa5603ff4c32d62de8442d1252f84c6777d12d14ca3be80538d5e69cc70e75363730427194cda709dee33da97452fcd4284898afebac2d5b298b10be30a89416afa66edfa46b3a396b880f030d5f2c64a7fcfd458ee8705f160cc98335cf7a7849908e33cd5af88a989c092c5453315436b0d3dd18f9357f68b37c95f30b5e3c6b1a29c39dd1c32af13c39398c137fa45334fd46b0601046818afa0710e38fb780fa47d8cf8392ce43461ef730fc8464fd4c39b75c27017e8a4344855edd16b7ac2e3a4c6a87a077314ada08def8ebde528c40e3d8b32f3ef9f9c8708020d86e99e89b3e5500aa6d9e628a2cc8b1dd17b0bbdd445f69c443b09433c3b8b94a6b1fd7e8af1b88cef8e6078dd010422e85ad3bd2d2e0344c7517f9530073c5f225c602eb61a138e13f79bf12c05bb01c61a2b13aed3d05d601ee42fa04af0ee6b2b37856b67e45348407ce43520e18e5bc639a9bfd0df9fedb8f91858bd3c220a78fc4aeeeaa8d7b3aa420964549b746fcb5b53177089b2ec59658c99b77e1b1e303233c041271a50c6e831379fd168f943563638341cca44ba63b3fe2fdd254386a4c325a881f3fb96f118169a56fed4b002f48bbfdfda728c50cff6529754359f29d44a66762f3a0ea39840a733852faa4a7be1ed6d8afc8291493cbdb55b17b4ef63dbe0f7bfb97c82986974f51a5da2b8dcdcf7f126f08389360164cd666f13ec64b9a63609c56fd154b6322f51d0b1d448dafe7806b59d00ce2fbbf34e6281f8c446012f124a4ea52955ff995dd642b1650cb4cdd9806038d2e3f3c0432a5a35307eae4ffdc49a8b9b83172804767ff8f082c8aa9e12315536ca6cb3b98cd80e438477ff5e53c9184db543fb6f3df0a7017bd9e513e83b707dd6917efd6990e609fd57abc1285e3e72899a1a6f0943539ea8e992050b681437a80b970f6e8d2bcdfa635acc270d7dec1b80bdb373dce18adb924b4ccf1ea61796a10f69eadb9da3ceea7e636e84fa0972e0cfea5237d19f488d31a0280e8a59f59dc44f825fd3bc41b92f1289042f45e892cab5a60a3036d594791143c737f2082cfcecf88f3a34d6cf6e50719c310e92e8e0fadbdce07f992006d5fc5869452ab572f6e4e864d5d72bde42d6ae26a909fa9a3964bc688052451e65a3612ef3e25392edd7388ebdeb3ee51d63ea3951a8ee653e7389d3a20cd7da5292fadad41e2decc398a9318d09d2b0c589c193f9411212e6eb76480adf62f6345e6b7ad980866cfe4921468618d3e29614450052be793c006e784f3180c97058aedd751a7db1b1d676285e7793acdc02642fbe45803ed837f6f518b63bf363ff2b73ac8215b5db7cebff2197467f5f89de7080cd83779ac94d0732deec47bd9473bdf5c45428e961d057c642336257390daa2784f82289941015e7ac2ff399710d4a123e30f9867a62c6ed1f07bfa5059487b558e9aeda68a6171b55c03f85c00fad075f57b344a84b0c098f922b89ed572e578e3d2951eeaa051d5f26339776f51f390af1f5fc62e6ea42fae34da1676d0410a96b7e1d3c88f37c753dcf6a19512c7f619aa0beb27b318c128f5728232b0fc86e4eb9dabca731ffbe8b09a93d82aa95010ef621ed33a319984d3e12b9e856d81f46602c7fe13d24716362ebfc70b43eb46495db78d2dbf509413a0162179023d22a4584f1421622e1151de4e4c80f12114b22d3d06f434a2f85cc5606cdad1d6fa3044a3dd6175049d137eb1a5d764715f1289dda9a8f55fd856275a3650ce7d67e20d025ef1c1c9c2a1f17613b41e4917edab30d31ae7d8c4351e9c8bb83726998e9cffc82f92d7ba1b1fd104d4f013a0496daf75ce2b50d21c4eb20c5d295832f3bd6501f6f1f491783aa476664e058cb2b4d22411bc5ecca5ec53b763f70e9223d9915c83b35e79aa86417b3505c8b952265c6a48ab266fade009c1faacce9d9a89516223593e5f1d5039f82ca0a043eceb78f5ea20d180b22d3f11a7ca5ae0792b5dc9685ba46fc87326eb468295f0890cf9338b69dabd5f826046e216bb7306333120bb36aa902f54dd28cbeb8580f3483cf69f8f9fdb3c7ff936f055f9323fa02db8237db7b2d6d26e137fc5fa728c387dbca015f34228915088a95fdfc09a5d2c42ea8189a1dff888ea53f52541232689ba396d96bffb13bab2d65f94a422ea762b6446d5a8e4e2f0c5b2398fcabba825e532a4bae96b45c2a88ca138ae9118653f71d1d9c7819755febcf15b203e1402522b2762985fdbd70dfc37cd0b6943d50cbbaf42f01b442e6f4445f986c09bc55835bb6a03431d1bfa1916db455c822972ff9fba37b2d4477cbf2138325949c4a15d1e0457b51cb06d35c9bf3478c79256989c36d9ec35b3d7f67eb23e476250f9424835be56ef00406c395d60c608100258b97cd51f853960c44ca48e2ea2696793e825db9e9a52ea840c8dd252273eec1212482738be81301acd8c79e5fd54b218c4e27b139c6e8eb5729b01326273a70f64785878dd3f0b10462bf11b152229dd5b1ef9d5cc7bffc44a85384163de88bb421a2999e0f01cec8b74c8dce0b0a40fd0409c26a9c967940592e61936a70f7c8be7d95d45b9a003b5dc1d33121cb7901afec1c8d98103e29d64a370ac6344600ceb067b921067ce2760a5a7e07c9396606458eb3f404713a8bb8d12211b64fd98bf9a88031cf9bbccab00a9f6a7b5c7033dfa90ff1aee6d95a9af74926ea83332523bbf4df7c4cd8769e0a56e50205b529bbafb37438c8ce05ed02e8dbcb6a60f03a0142e701ab2d2520e159ac2c5ce1a2d0f342bc837f60c7ca912241a55d8ed174f9b714950cc7d3eddd06d23f31d6fc46eb2bc248cfcac8fbb7a0d8bc6f972c9bd9f5ef29942bac1b117675c33664b50fcc6f049528b76dc2fffa766fca42c2968ff6960e33efd2984db268412543c07682f0ddb9bd59ce111820d6f1bd1a76063b0c60479b19b8a49631a722747c6d20133a77f7072330c134d006352e44443230c7eddfc9fd645a50b3e3ee780ef7097198d7c87ad9969d4afe414314b57f248e4237dc164e084be7534f2c3c55f5110fe7d202a5737f067b7a282f8090cfcdd2d34f64aee499c075e50f480272e3d981b3c0e553b8bd04279dcd0097cc035d8016f4e4d40d3b5526b617533e1f1db0d90b4071bd4e2ada7b6ad172beff1edda9c8c750f77895880a0cea9c5b35f70cc32d9b83d088ae66662182c0f41db5c3faaacd7773846d7cee72d3748533ec9983964749f1f5694218d357ecab2d330206dfc11dfaa5c29a6441890faf607d73f33732c07097da08d84231eed7346e706d24bc695df684c6670cc5b10662638f7c01534833f8b6fc6eab95f3841cea2069b7a25d97c390b58d04519a62bc93c56803ee773ba80309917202ddf8fe9cb128869a42e206126c282c4e896e74981db12f4d0f2bddec9a674b75c86e8cbd18d29ddca4dadc11141d066ebe424ace546ec974a6ec8b7ee352fcdc96a88a65c90166cd9c8b5b03640614632aa3eb0d1516b40128b065c3e377ceac6a5be1217351da75534c9d651d80551b3150732389e35025d0769bbb3d9885e83450eb262ed091bcd181979ecfc56d2301b3d3c7941e52a55f7e3460e1056612010cd286aa193a5dbe015b22bca180f239c36eeacbb6f6d5884f469163260fdf015203a8523059d8da4b869be00cb938d318a8215b212dd0bd6a7bd6e336bca3c67ba74872eb19c450982796d794b013f27e3cf889a928fcd94caff8692a29266befe74420edd2117bf947d4730dda838640128bdb17869eab8dfa228d4c4bb5ff5b00a57c6c8d1123487039338e3f342cf273e0e4995e95ff4c8e2a23974bf16c20f5443c21eb9aadf69aaacefddeacb2844f9a5f354cad0a94af5be824e9a2ec4c03828fdab7415d9be05372e8c515c0cd5fcd44e69f1b380df484c860539773ce68b402a6585fcd826a92ce05162cf7f17ca02d7fdd80b9cfa8bb3a37cf62ff6f3ecbe03c186075a5dbce6e36fe46ed9059fa60e347c978f0f3b71bc9d05e4a4e1ce6b48e0593a1acdf9899f4d709e005b972411349fda2c544396eb73c10d89c6db2b5a7506a34d7f5b66b3ff37e8088f2dcd9c2dd76b21818674f8ceb8bbda6c38b58dd5f5de09c8a25949e28aa04a8ccba10275c032309e9b61de148f8495640cfbf3d46e342c3859bfb5e6ab10b4df4a39bc20a2eb48fbaee4c01f5661b4129b15414842eaa46154c77df5484fab490185cfa83f21ec5b72abfa507b6b998654aec4b1031ac1dfc919022423d6020fa1a702fd65f98e0b6f64210f7d2d326de960a51c7c5b357c42073fac112a393c7f40a0f368600ba00010530aa782460098f559f42b37d3510afb425a249c0c17cf0380c40793b068d565fcc2fd70df74dc2b8cbda4849164c30631554517f0ba2c9e94977959012bc7f371b5c375214a5ed4f2d3920746cb5a01c0356c187bb186a7d5ae7bd57e13befa101813dce482b49ad0d41fbe5bc542cf55445136db1f8442003e48a75bb6637be93626178bed28402c91610d067d94d06136b337d4ada511376a84fb6bde4215828359058cb2f5b1d0281ff93743d43b8881d4f7591800166621141cca2b122f1ed63baaca752f7de0cf6d2e92dc6caa2a43df580d8b472400065aeeffc71d5a7a5f52f02d26a26225c53591a60e29a8ae7e9cd0d3f9f8ab8bb5176ae1fd4e881db04f8239b282123147036019a560fb450baf8fc3dbaa7989c04e8e8f674acdadf59048f7fcc5efd8ac3577e9204837dd6bec8c72c52d019e9172825ff27bc9cef950d729a02c26e00167872c53a2c303cb260035a5184519cdb9dc0ae32b1b3d0375b248fe4c5b98a37368cf0d548c48904d87d4f3ff4e9a989b3f28a5747cfd5f7a67d3b8dc30bdf709bfa56075d28e375d24c7409ff442913c1209f1587f8e252a35c6bfdcf581d7fb1bd693329eafd872078de4c1b31a7d5d5f3466adf41b0ee17c9aba8b88bbba6a868ddddfed5085947da0859d16641abc2e869e7a120c807d1a2092ed79f43f287dfdffc044cd3c246f87dc12727dc8b6151ea19f1d919ebd23ba46e5ae7fcc7cfd7a746db70dd0adeef889e5ae74941fbe7f97021fc95e8423ba91b735d8e9587f5ad515d595600abc96c08d796e640def566e990d9f4c6a5e7270f949284221c81df4e57a9c129a45d508820938365093d6dd672f4d4418c7bff35ca1603aa068beeee04060251722f04718303e1fd4c5bc64ef07b13408516ec92581d2de93a93693148ba416615fe1f1b64d5bd8975777337242e0ea9f7586599fdba8dd87c81a4c6bf4eab14d6ebac32cb3310cbbe5cf23620973b4ed7e688bec9e2d5569594c2377ba60f998750dd828bc704aeda55f5608ea12649e91a3733cb9b4a34d9886ea6b4a8d2cfbd883b9997ef1042f8d40b4cd870698585bb409cd5c21365d38e3c95dcd91244a62d766ba728aa822390c2def2166c46f45c275790f2a6dd11f906312214c120bf27efda0afd4cd8d6482d16a4ab72d2e69a49cb3e1b4ebb9025d81479fd2ccb4f66eee4248657c3f8dca13aa7201824bff06c543e0200c4cdff612ab0bb29b89fdb82c3a7abb14edd78f6e224c61c4d3d3b1c1c7038aa54afb4d32c3039d58e057185906c89887cc101b577c97b363d7c587c652a358c4025f690be410171b2c76723433da12a9163a4420f13aa\",\"cipherparams\":{\"iv\":\"664b1a53b2ecf34d3305397defd89b38\"},\"kdf\":\"scrypt\",\"kdfparams\":{\"dklen\":48,\"n\":262144,\"p\":1,\"r\":8,\"salt\":\"d48fb344fbec36d5a3787e4271561bdc61a6c100e20641521fceba2af6bc0668\"},\"mac\":\"ba8bebc33fe945df3340b9e761c199304655ac1c24dbef92b69cc5e6a84fb649\"},\"id\":\"a4d92ffd-9dc9-41ab-9eaa-04ef14b8a4bc\",\"version\":4}";
237
- console.log(walletEncryptedJson);
238
- let wallet = qcsdk.deserializeEncryptedWallet(walletEncryptedJson, examplePassphrase);
239
- if (wallet === null) {
240
- console.log("Error opening wallet");
241
- } else {
242
- console.log("From wallet address: " + wallet.address);
243
- }
244
- console.log("Note: This wallet needs to have sufficient balance for gas fees\n");
245
-
246
- try {
247
- // Get nonce from RPC
248
- const nonce = await getTransactionCount(wallet.address);
249
- console.log("Nonce (transaction count) is:", nonce);
250
-
251
- // Verify that bytecode has been set
252
- if (CONTRACT_BYTECODE === "0xPLACEHOLDER_REPLACE_WITH_COMPILED_BYTECODE" || CONTRACT_BYTECODE.length < 10) {
253
- console.error("\n❌ ERROR: CONTRACT_BYTECODE has not been set!");
254
- console.error("Please compile the Solidity contract and update CONTRACT_BYTECODE with the actual bytecode.");
255
- console.error("Steps:");
256
- console.error("1. Download solc.exe from: https://github.com/quantumcoinproject/Solidity/releases/tag/v32b.8.12");
257
- console.error("2. Save the Solidity code from the comments above to SimpleStorage.sol");
258
- console.error("3. Run: c:\\gethbuild\\solc.exe --bin SimpleStorage.sol");
259
- console.error("4. Copy the bytecode from the 'Binary:' section");
260
- console.error("5. Paste it in CONTRACT_BYTECODE variable, ensuring it starts with '0x'\n");
261
- return;
262
- }
263
-
264
- // Contract creation parameters
265
- const toAddress = null; // null for contract creation
266
- const valueInWei = "0x0"; // No value sent with contract creation (or use BigInt(0))
267
- const remarks = null; // No remarks
268
-
269
- // Pack contract creation data using packCreateContractData
270
- // This matches the Go pattern: Pack("", params...) and append(bytecode, input...)
271
- // For a constructor with no parameters, we pass no args
272
- console.log("Packing contract creation data...");
273
- const CONTRACT_ABI = [
274
- {
275
- "type": "constructor",
276
- "inputs": [],
277
- "stateMutability": "nonpayable"
278
- }
279
- ];
280
- const abiJSON = JSON.stringify(CONTRACT_ABI);
281
- const packResult = qcsdk.packCreateContractData(abiJSON, CONTRACT_BYTECODE /* no constructor params */);
282
-
283
- if (packResult.error) {
284
- console.error("❌ Error packing contract creation data:", packResult.error);
285
- return;
286
- }
287
-
288
- const data = packResult.result; // Packed bytecode + constructor data
289
- console.log("Contract creation data packed successfully");
290
- console.log("Data length:", data.length, "characters");
291
-
292
- // Calculate and display the contract address that will be created
293
- console.log("\nCalculating contract address...");
294
- const contractAddress = qcsdk.createAddress(wallet.address, nonce);
295
- if (contractAddress) {
296
- console.log("✅ Contract will be deployed at address:", contractAddress);
297
- } else {
298
- console.warn("⚠️ Could not calculate contract address");
299
- }
300
-
301
- // Estimate gas for contract creation
302
- console.log("Estimating gas for contract creation...");
303
- let gasLimit;
304
- try {
305
- const estimatedGas = await estimateGas(wallet.address, toAddress, valueInWei, data);
306
- console.log("Estimated gas:", estimatedGas);
307
-
308
- // Add 20% buffer to estimated gas to ensure transaction doesn't fail
309
- const gasBuffer = Math.ceil(estimatedGas * 0.2);
310
- gasLimit = estimatedGas + gasBuffer;
311
- console.log("Gas limit (with 20% buffer):", gasLimit);
312
- } catch (error) {
313
- console.warn("⚠️ Could not estimate gas, using default gas limit:", error.message);
314
- // Fallback to a default gas limit if estimation fails
315
- gasLimit = 500000;
316
- console.log("Using default gas limit:", gasLimit);
317
- }
318
-
319
- // Calculate gas price (fixed: 1000 coins per 21000 gas)
320
- console.log("\nCalculating gas price...");
321
- const gasPrice = getGasPrice();
322
- console.log("Gas price (wei per gas unit):", gasPrice.toString());
323
- console.log("Note: QuantumCoin uses a fixed rate of 1000 coins per 21000 gas units");
324
-
325
- // Calculate total fee
326
- const totalFeeWei = BigInt(gasLimit) * gasPrice;
327
- const totalFeeCoins = weiToCoins(totalFeeWei);
328
-
329
- // Display transaction details and request confirmation
330
- console.log("\n" + "=".repeat(60));
331
- console.log("TRANSACTION DETAILS");
332
- console.log("=".repeat(60));
333
- console.log("Gas Limit: ", gasLimit.toLocaleString());
334
- console.log("Gas Price: ", gasPrice.toString(), "wei");
335
- console.log("Total Fee: ", totalFeeWei.toString(), "wei");
336
- console.log("Total Fee: ", totalFeeCoins.toFixed(9), "coins");
337
- console.log("=".repeat(60));
338
-
339
- // Request user confirmation
340
- const confirmation = await promptUser("\nDo you want to proceed with this transaction? (yes/no): ");
341
-
342
- if (confirmation !== 'yes' && confirmation !== 'y') {
343
- console.log("Transaction cancelled by user.");
344
- return;
345
- }
346
-
347
- console.log("\nProceeding with transaction...");
348
-
349
- // Create transaction signing request
350
- const transactionRequest = new qcsdk.TransactionSigningRequest(
351
- wallet,
352
- toAddress, // null for contract creation
353
- valueInWei,
354
- nonce,
355
- data, // Contract bytecode
356
- gasLimit,
357
- remarks
358
- );
359
-
360
- // Sign the transaction
361
- console.log("\nSigning transaction...");
362
- const signResult = qcsdk.signRawTransaction(transactionRequest);
363
-
364
- if (signResult.resultCode !== 0) {
365
- console.error("Failed to sign transaction. Result code:", signResult.resultCode);
366
- return;
367
- }
368
-
369
- console.log("Transaction signed successfully");
370
- console.log("Transaction hash:", signResult.txnHash);
371
- console.log("Transaction data length:", signResult.txnData.length, "characters");
372
- console.log("Transaction data:", signResult.txnData);
373
-
374
- // Send transaction via RPC
375
- console.log("\nSending transaction to network...");
376
- try {
377
- const txHash = await sendRawTransaction(signResult.txnData);
378
- console.log("✅ Transaction submitted successfully!");
379
- console.log("Transaction hash from RPC:", txHash);
380
- if (contractAddress) {
381
- console.log("\n📝 Contract Address:", contractAddress);
382
- console.log("Note: The contract will be deployed at the address shown above once the transaction is confirmed.");
383
- } else {
384
- console.log("\nNote: The contract will be deployed at an address determined by the transaction.");
385
- }
386
- console.log("You can check the transaction status on the block explorer.");
387
- } catch (error) {
388
- console.error("❌ Error sending transaction:", error.message);
389
- console.error("Make sure the wallet has sufficient balance for gas fees.");
390
- }
391
-
392
- } catch (error) {
393
- console.error("Error creating contract:", error);
394
- }
395
- });
396
-