@secondlayer/cli 0.1.1 → 0.2.1

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 DELETED
@@ -1,222 +0,0 @@
1
- # @secondlayer/cli
2
-
3
- Generate fully typed contract interfaces, functions, and React hooks for Clarity smart contracts.
4
-
5
- ## Usage
6
-
7
- ### 1. Utilize the generated contract interfaces with familiar libraries
8
- ```typescript
9
- // Usage with `@stacks/transactions`
10
- import { mega } from './generated/contracts'
11
- import { fetchCallReadOnlyFunction, makeContractCall } from '@stacks/transactions'
12
-
13
- await makeContractCall({
14
- ...mega.callback({
15
- sender: "SPKPXQ0X3A4D1KZ4XTP1GABJX1N36VW10D02TK9X",
16
- memo: "Hello world",
17
- }),
18
- network: 'mainnet',
19
- })
20
-
21
- await fetchCallReadOnlyFunction({
22
- ...mega.getBalance(),
23
- network: 'mainnet'
24
- })
25
- ```
26
-
27
- ### 2. Use built-in read/write helpers
28
- ```typescript
29
- // Read helpers
30
- const balance = await mega.read.getBalance() // {type: 'uint', value: 42000000n}
31
-
32
- // Write helpers
33
- const result = await mega.write.transfer(
34
- {
35
- amount: 10000n,
36
- recipient: "SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335",
37
- },
38
- {
39
- senderKey: "b244296d5907de9864c0b0d51f98a13c52890be0404e83f273144cd5b9960eed01",
40
- }
41
- );
42
- ```
43
-
44
- ### 3. React integration
45
- ```typescript
46
- import { useBnsV2Transfer } from './generated/hooks'
47
-
48
- function App() {
49
- const { transfer, isRequestPending } = useBnsV2Transfer()
50
-
51
- return (
52
- <button
53
- onClick={() => transfer({
54
- id: 1n,
55
- owner: 'SP...',
56
- recipient: 'SP...'
57
- })}
58
- disabled={isRequestPending}
59
- >
60
- Transfer
61
- </button>
62
- )
63
- }
64
- ```
65
-
66
- ## Installation
67
-
68
- > **Note:** This package is not yet published to npm. For now, you can install it locally:
69
-
70
- ```bash
71
- bun add -g @secondlayer/cli
72
- ```
73
- ## Setup
74
-
75
- To create a `stacks.config.ts` file, run `secondlayer init` in your Clarinet project:
76
-
77
- ```bash
78
- secondlayer init
79
- ```
80
-
81
- ```typescript
82
- // stacks.config.ts
83
- import { defineConfig } from '@secondlayer/cli'
84
- import { clarinet } from '@secondlayer/cli/plugins'
85
-
86
- export default defineConfig({
87
- out: 'src/generated.ts',
88
- plugins: [clarinet()],
89
- })
90
- ```
91
-
92
- Run `secondlayer generate` to create fully type-safe interfaces for your contracts.
93
-
94
- ```bash
95
- secondlayer generate
96
- ✔ Generation complete for 2 contracts
97
- 📄 ./src/generated/contracts.ts
98
- ```
99
-
100
- ## Advanced
101
-
102
- ### Plugins
103
-
104
- ```typescript
105
- import { defineConfig } from '@secondlayer/cli'
106
- import { clarinet, actions, react, hiro } from '@secondlayer/cli/plugins'
107
-
108
- export default defineConfig({
109
- out: 'src/generated.ts',
110
- plugins: [
111
- clarinet(), // Generate contract interfaces from local Clarinet project
112
- actions(), // Add read/write helper functions
113
- react(), // Generate React hooks
114
- hiro({ // Generate contract interfaces using the Hiro API
115
- apiKey: process.env.HIRO_API_KEY!,
116
- network: 'mainnet',
117
- contracts: [
118
- 'SP466FNC0P7JWTNM2R9T199QRZN1MYEDTAR0KP27.miamicoin-core-v1',
119
- ],
120
- }),
121
- ],
122
- })
123
- ```
124
-
125
- ## Future Enhancements
126
-
127
- #### Add `testing()` plugin for unit testing
128
-
129
- Currently, Clarinet JS SDK users must manually convert JS values to Clarity types, recall contract signatures, and write boilerplate for common tests.
130
-
131
- _Solution:_ Enable zero-config Clarinet detection and auto-run code generation within the dev workflow.
132
-
133
- ```typescript
134
- import { describe, it, expect, beforeAll } from 'vitest';
135
- import { initSimnet } from '@hirosystems/clarinet-sdk';
136
- import { tokenContract } from './generated/helpers';
137
-
138
- describe('Token Contract', () => {
139
- let simnet;
140
-
141
- beforeAll(async () => {
142
- simnet = await initSimnet();
143
- });
144
-
145
- it('transfers tokens', async () => {
146
- // Clean, focused API for testing
147
- const result = await tokenContract.transfer({
148
- amount: 1000n,
149
- sender: 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM',
150
- recipient: 'ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG'
151
- }, 'wallet_1');
152
-
153
- expect(result).toBeOk();
154
- });
155
- });
156
- ```
157
-
158
- #### Converting responses using `cvToValue`
159
-
160
- Currently, when calling read-only functions or receiving blockchain responses, developers must manually extract values from Clarity value objects that include type metadata (e.g., `{ type: "uint", value: 42000n }`). This requires repetitive boilerplate code to access the actual values.
161
-
162
- _Solution:_ Provide automatic Clarity value conversion with full TypeScript type inference, extracting raw values while preserving complete type safety.
163
-
164
- ```typescript
165
- import { daoContract } from './generated/contracts';
166
-
167
- // Before
168
- const result = await daoContract.read.getProposal(proposalId);
169
- // Returns complex nested structure:
170
- // {
171
- // type: "tuple",
172
- // value: {
173
- // id: { type: "uint", value: 1n },
174
- // proposer: { type: "principal", value: "SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7" },
175
- // title: { type: "string-utf8", value: "Increase Treasury Allocation" },
176
- // votesFor: { type: "uint", value: 150000n },
177
- // votesAgainst: { type: "uint", value: 50000n },
178
- // startBlock: { type: "uint", value: 120500n },
179
- // endBlock: { type: "uint", value: 125500n },
180
- // executed: { type: "bool", value: false }
181
- // }
182
- // }
183
-
184
- // Tedious extraction needed:
185
- return {
186
- id: result.value.id.value,
187
- proposer: result.value.proposer.value,
188
- title: result.value.title.value,
189
- votesFor: result.value.votesFor.value,
190
- votesAgainst: result.value.votesAgainst.value,
191
- startBlock: result.value.startBlock.value,
192
- endBlock: result.value.endBlock.value,
193
- executed: result.value.executed.value
194
- };
195
-
196
- // After
197
- const proposal = await daoContract.read.getProposal(proposalId);
198
- // Returns clean TypeScript object directly:
199
- // {
200
- // id: 1n,
201
- // proposer: "SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",
202
- // title: "Increase Treasury Allocation",
203
- // votesFor: 150000n,
204
- // votesAgainst: 50000n,
205
- // startBlock: 120500n,
206
- // endBlock: 125500n,
207
- // executed: false
208
- // }
209
-
210
- // Full type safety and IntelliSense:
211
- console.log(proposal.endBlock); // ✅ TypeScript knows this is bigint
212
- console.log(proposal.title); // ✅ TypeScript knows this is string
213
- console.log(proposal.executed); // ✅ TypeScript knows this is boolean
214
-
215
- return proposal;
216
- ```
217
-
218
- #### More hooks
219
-
220
- ## License
221
-
222
- MIT