quantumcoin 7.0.1 → 7.0.3
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/.gitignore +3 -0
- package/README-SDK.md +64 -10
- package/README.md +27 -4
- package/SPEC.md +3843 -0
- package/examples/AllSolidityTypes.sol +184 -0
- package/examples/SimpleIERC20.sol +74 -0
- package/examples/example-generator-sdk-js.js +95 -0
- package/examples/example-generator-sdk-ts.js +95 -0
- package/examples/example.js +2 -2
- package/examples/offline-signing.js +73 -0
- package/examples/package-lock.json +10 -1103
- package/examples/package.json +1 -2
- package/examples/read-operations.js +1 -2
- package/examples/sdk-generator-erc20.inline.json +251 -0
- package/examples/solidity-types.ts +43 -0
- package/generate-sdk.js +689 -87
- package/package.json +30 -9
- package/src/abi/interface.d.ts +18 -0
- package/src/abi/interface.js +247 -9
- package/src/abi/js-abi-coder.js +474 -0
- package/src/contract/contract-factory.d.ts +1 -1
- package/src/contract/contract-factory.js +14 -2
- package/src/contract/contract.d.ts +10 -1
- package/src/contract/contract.js +42 -0
- package/src/generator/index.js +1041 -63
- package/src/index.d.ts +16 -0
- package/src/providers/provider.d.ts +20 -11
- package/src/providers/provider.js +12 -0
- package/src/types/index.d.ts +462 -0
- package/src/types/index.js +9 -0
- package/test/e2e/all-solidity-types.dynamic.test.js +200 -0
- package/test/e2e/all-solidity-types.fixtures.js +231 -0
- package/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +368 -0
- package/test/e2e/simple-erc20.generated-sdks.e2e.test.js +151 -0
- package/test/e2e/transactional.test.js +4 -4
- package/test/e2e/typed-generator.e2e.test.js +8 -6
- package/test/integration/ws-provider.test.js +1 -1
- package/test/unit/generate-contract-cli.test.js +2 -1
- package/test/unit/generate-sdk-artifacts-json.test.js +45 -0
- package/test/unit/generator.test.js +1 -0
- package/test/unit/populate-transaction.test.js +62 -0
- package/test/unit/solidity-types.test.js +46 -0
- package/test/unit/utils.test.js +1 -1
package/.gitignore
CHANGED
package/README-SDK.md
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
This is an experimental SDK. Use at your own risk.
|
|
3
|
-
-->
|
|
1
|
+
> **CAUTION:** This is an experimental SDK. Use at your own risk.
|
|
4
2
|
|
|
5
3
|
# QuantumCoin.js — Comprehensive SDK Documentation
|
|
6
4
|
|
|
@@ -563,6 +561,35 @@ From `quantumcoin`:
|
|
|
563
561
|
**Example(s):**
|
|
564
562
|
- `examples/wallet-offline.js`
|
|
565
563
|
|
|
564
|
+
## Solidity Types (TypeScript)
|
|
565
|
+
|
|
566
|
+
QuantumCoin.js exposes core Solidity-related types for TypeScript users.
|
|
567
|
+
|
|
568
|
+
- **Import path**: `quantumcoin/types`
|
|
569
|
+
|
|
570
|
+
**Key exports**
|
|
571
|
+
|
|
572
|
+
- `AddressLike` (currently `string`, 32-byte address)
|
|
573
|
+
- `BytesLike` (`string | Uint8Array`)
|
|
574
|
+
- `BigNumberish` (`string | number | bigint`)
|
|
575
|
+
- `SolidityTypeName` (ABI type string model)
|
|
576
|
+
- **Hard Solidity aliases** (preferred for typed wrappers):
|
|
577
|
+
- Integers: `Uint256Like` / `Uint256`, `Int256Like` / `Int256` (and all widths `Uint8Like`…`Uint256Like`, `Int8Like`…`Int256Like`)
|
|
578
|
+
- Fixed bytes: `Bytes32Like` / `Bytes32` (and `Bytes1Like`…`Bytes32Like`)
|
|
579
|
+
- Arrays/tuples helpers: `SolArray<T>`, `SolFixedArray<T, N>`, `SolStruct<T>`
|
|
580
|
+
- `SolidityInputValue<T>` / `SolidityOutputValue<T>` (advanced type-level mapping from ABI type strings to JS values; the generator no longer uses these for wrapper signatures)
|
|
581
|
+
|
|
582
|
+
Example:
|
|
583
|
+
|
|
584
|
+
```ts
|
|
585
|
+
import type { AddressLike, BigNumberish, Uint256Like, Uint256 } from "quantumcoin/types";
|
|
586
|
+
|
|
587
|
+
const to: AddressLike = "0x0000000000000000000000000000000000000000000000000000000000001000";
|
|
588
|
+
const amount: BigNumberish = "123";
|
|
589
|
+
const asInput: Uint256Like = amount;
|
|
590
|
+
const asOutput: Uint256 = 123n;
|
|
591
|
+
```
|
|
592
|
+
|
|
566
593
|
### Encoding utilities
|
|
567
594
|
|
|
568
595
|
- `toUtf8String(data: BytesLike): string`
|
|
@@ -625,11 +652,24 @@ From `quantumcoin`:
|
|
|
625
652
|
|
|
626
653
|
### Overview
|
|
627
654
|
|
|
628
|
-
`generate-sdk.js` creates **typed
|
|
655
|
+
`generate-sdk.js` creates **typed contract wrappers** for one or more contracts, and can optionally scaffold a complete npm package (with examples and transactional tests).
|
|
656
|
+
|
|
657
|
+
It supports generating:
|
|
658
|
+
- **TypeScript source** (`--lang ts`, default)
|
|
659
|
+
- **JavaScript source + TypeScript declarations** (`--lang js`)
|
|
660
|
+
|
|
661
|
+
**Typing behaviour (generated wrappers)**
|
|
662
|
+
|
|
663
|
+
- **Hard types**: wrapper signatures use concrete types from `quantumcoin/types` (e.g. `Uint256Like` for inputs, `Uint256` for outputs).
|
|
664
|
+
- **Single output unwrapping**: functions returning one value return the value directly (not `[value]`).
|
|
665
|
+
- **Multiple outputs**: returned as a tuple type (e.g. `Promise<[Uint256, Bool]>`).
|
|
666
|
+
- **No outputs**: `Promise<void>`.
|
|
667
|
+
- **Structs / tuples**: emitted as `export type <Name>Input` / `export type <Name>Output` and used in signatures.
|
|
668
|
+
- **JS typing**: JS output uses JSDoc types plus `.d.ts` files; TS users still get strong types.
|
|
629
669
|
|
|
630
670
|
**Entry point**
|
|
631
671
|
- `node generate-sdk.js ...`
|
|
632
|
-
- or `npx
|
|
672
|
+
- or `npx sdkgen ...` (when installed)
|
|
633
673
|
|
|
634
674
|
### Input modes
|
|
635
675
|
|
|
@@ -637,12 +677,18 @@ From `quantumcoin`:
|
|
|
637
677
|
|
|
638
678
|
```bash
|
|
639
679
|
node generate-sdk.js --abi path/to/My.abi.json --bin path/to/My.bin --name MyContract --out ./out --non-interactive
|
|
680
|
+
|
|
681
|
+
# JS output
|
|
682
|
+
node generate-sdk.js --lang js --abi path/to/My.abi.json --bin path/to/My.bin --name MyContract --out ./out --non-interactive
|
|
640
683
|
```
|
|
641
684
|
|
|
642
685
|
2) **Solidity sources**
|
|
643
686
|
|
|
644
687
|
```bash
|
|
645
688
|
node generate-sdk.js --sol ".\\contracts\\A.sol,.\\contracts\\B.sol" --solc "c:\\solc\\solc.exe" --out ./out --non-interactive
|
|
689
|
+
|
|
690
|
+
# Pass additional solc args (example)
|
|
691
|
+
node generate-sdk.js --sol ".\\contracts\\A.sol" --solc "c:\\solc\\solc.exe" --solc-args "--via-ir --evm-version london" --out ./out --non-interactive
|
|
646
692
|
```
|
|
647
693
|
|
|
648
694
|
3) **Artifacts JSON (multi-contract ABI+BIN list)**
|
|
@@ -656,16 +702,22 @@ Example `artifacts.json`:
|
|
|
656
702
|
```json
|
|
657
703
|
[
|
|
658
704
|
{ "abi": "./Alpha.abi.json", "bin": "./Alpha.bin" },
|
|
659
|
-
{ "abi": "./Beta.abi.json", "bin": "./Beta.bin", "name": "Beta" }
|
|
705
|
+
{ "abi": "./Beta.abi.json", "bin": "./Beta.bin", "name": "Beta" },
|
|
706
|
+
{
|
|
707
|
+
"name": "Gamma",
|
|
708
|
+
"abi": "[{\"type\":\"function\",\"name\":\"set\",\"stateMutability\":\"nonpayable\",\"inputs\":[{\"name\":\"value\",\"type\":\"uint256\"}],\"outputs\":[]}]",
|
|
709
|
+
"bin": "0x6000600055..."
|
|
710
|
+
}
|
|
660
711
|
]
|
|
661
712
|
```
|
|
662
713
|
|
|
663
714
|
### Package scaffolding mode
|
|
664
715
|
|
|
665
|
-
Use `--create-package` to create a full npm package (source, tests, examples, README
|
|
716
|
+
Use `--create-package` to create a full npm package (source, tests, examples, README).
|
|
666
717
|
|
|
667
718
|
```bash
|
|
668
719
|
node generate-sdk.js --artifacts-json .\\artifacts.json ^
|
|
720
|
+
--lang ts ^
|
|
669
721
|
--create-package --package-dir .\\tmp --package-name my-typed-package ^
|
|
670
722
|
--package-description "My typed package" --package-author "me" ^
|
|
671
723
|
--package-license MIT --package-version 0.0.1 ^
|
|
@@ -676,11 +728,13 @@ node generate-sdk.js --artifacts-json .\\artifacts.json ^
|
|
|
676
728
|
|
|
677
729
|
When `--create-package` is used, the generator produces:
|
|
678
730
|
|
|
679
|
-
- `src/`
|
|
731
|
+
- `src/` contract wrappers + factories
|
|
732
|
+
- TS mode: `*.ts` (compiled output in `dist/` after `npm run build:ts`)
|
|
733
|
+
- JS mode: `*.js` with `*.d.ts` types (no build step required)
|
|
680
734
|
- `test/e2e/*.e2e.test.js` per-contract transactional tests
|
|
681
735
|
- `examples/` deploy/read/write/events scripts
|
|
682
|
-
- `
|
|
683
|
-
- `
|
|
736
|
+
- `README.md` generated by the generator (includes ABI-derived API overview)
|
|
737
|
+
- `index.js` + `index.d.ts` (package entry shims)
|
|
684
738
|
|
|
685
739
|
### Running generated transactional tests
|
|
686
740
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
This is an experimental SDK. Use at your own risk.
|
|
3
|
-
-->
|
|
1
|
+
> **CAUTION:** This is an experimental SDK. Use at your own risk.
|
|
4
2
|
|
|
5
3
|
**Comprehensive SDK documentation:** see [`README-SDK.md`](./README-SDK.md).
|
|
6
4
|
|
|
@@ -84,13 +82,38 @@ This repo includes a generator described in `SPEC.md` section 15.
|
|
|
84
82
|
# Non-interactive
|
|
85
83
|
node generate-sdk.js --abi path/to/abi.json --bin path/to/bytecode.bin --out ./generated --name MyContract --non-interactive
|
|
86
84
|
|
|
85
|
+
# JavaScript output (with TypeScript `.d.ts` types)
|
|
86
|
+
node generate-sdk.js --lang js --abi path/to/abi.json --bin path/to/bytecode.bin --out ./generated --name MyContract --non-interactive
|
|
87
|
+
|
|
87
88
|
# Interactive
|
|
88
89
|
node generate-sdk.js --abi path/to/abi.json --bin path/to/bytecode.bin
|
|
89
90
|
```
|
|
90
91
|
|
|
91
92
|
If installed as a package, you can also run:
|
|
92
93
|
|
|
93
|
-
`npx
|
|
94
|
+
`npx sdkgen --abi ... --bin ...`
|
|
95
|
+
|
|
96
|
+
### Generator typing model
|
|
97
|
+
|
|
98
|
+
- **Hard types**: generated wrappers use concrete types from `quantumcoin/types` (e.g. `Uint256Like` for inputs, `Uint256` for outputs).
|
|
99
|
+
- **Single return values are unwrapped**: a Solidity function returning one value returns that value directly (not `[value]`).
|
|
100
|
+
- **Multiple returns**: returned as a tuple type (e.g. `Promise<[Uint256, Bool]>`).
|
|
101
|
+
- **No returns**: `Promise<void>`.
|
|
102
|
+
- **Structs / tuples**: generated as `export type <Name>Input` / `export type <Name>Output` and used directly in method signatures.
|
|
103
|
+
|
|
104
|
+
## Solidity types (TypeScript)
|
|
105
|
+
|
|
106
|
+
QuantumCoin.js exports core Solidity-related typings from:
|
|
107
|
+
|
|
108
|
+
- `quantumcoin/types`
|
|
109
|
+
|
|
110
|
+
Common types:
|
|
111
|
+
|
|
112
|
+
- `AddressLike` (currently `string`, 32-byte address)
|
|
113
|
+
- `BytesLike` (`string | Uint8Array`)
|
|
114
|
+
- `BigNumberish` (`string | number | bigint`)
|
|
115
|
+
- **Hard Solidity aliases** (preferred for typed wrappers): `Uint256Like` / `Uint256`, `Int256Like` / `Int256`, `Bytes32Like` / `Bytes32`, and all widths `Uint8Like`…`Uint256Like`, `Int8Like`…`Int256Like`, plus `Bytes1Like`…`Bytes32Like`
|
|
116
|
+
- `SolidityTypeName`, `SolidityInputValue<T>`, `SolidityOutputValue<T>` (advanced type-level mapping helpers; the generator no longer uses these for wrapper signatures)
|
|
94
117
|
|
|
95
118
|
## Examples
|
|
96
119
|
|