@satoshai/kit 0.1.0 → 0.1.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 +185 -0
- package/package.json +11 -11
- package/LICENSE +0 -21
package/README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# @satoshai/kit
|
|
2
|
+
|
|
3
|
+
Typesafe Stacks wallet & contract interaction library for React. Wagmi-inspired hook API for connecting wallets, signing messages, and calling contracts on the Stacks blockchain.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **`StacksWalletProvider`** — React context provider for wallet state
|
|
8
|
+
- **`useConnect` / `useDisconnect`** — Connect and disconnect wallets
|
|
9
|
+
- **`useAddress`** — Access connected wallet address and status
|
|
10
|
+
- **`useSignMessage`** — Sign arbitrary messages
|
|
11
|
+
- **`useWriteContract`** — Call smart contracts with post-conditions
|
|
12
|
+
- **`useBnsName`** — Resolve BNS v2 names
|
|
13
|
+
- **6 wallets supported** — Xverse, Leather, OKX, Asigna, Fordefi, WalletConnect
|
|
14
|
+
- **Next.js App Router compatible** — `"use client"` directives included
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pnpm add @satoshai/kit @stacks/transactions react react-dom
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { StacksWalletProvider, useConnect, useAddress, useDisconnect } from '@satoshai/kit';
|
|
26
|
+
|
|
27
|
+
function App() {
|
|
28
|
+
return (
|
|
29
|
+
<StacksWalletProvider>
|
|
30
|
+
<Wallet />
|
|
31
|
+
</StacksWalletProvider>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function Wallet() {
|
|
36
|
+
const { connect, connectors } = useConnect();
|
|
37
|
+
const { address, isConnected } = useAddress();
|
|
38
|
+
const { disconnect } = useDisconnect();
|
|
39
|
+
|
|
40
|
+
if (isConnected) {
|
|
41
|
+
return (
|
|
42
|
+
<div>
|
|
43
|
+
<p>Connected: {address}</p>
|
|
44
|
+
<button onClick={() => disconnect()}>Disconnect</button>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div>
|
|
51
|
+
{connectors.map((wallet) => (
|
|
52
|
+
<button key={wallet} onClick={() => connect(wallet)}>
|
|
53
|
+
{wallet}
|
|
54
|
+
</button>
|
|
55
|
+
))}
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## API
|
|
62
|
+
|
|
63
|
+
### `<StacksWalletProvider>`
|
|
64
|
+
|
|
65
|
+
Wrap your app to provide wallet context to all hooks.
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
<StacksWalletProvider
|
|
69
|
+
walletConnect={{ projectId: '...' }} // optional — enables WalletConnect
|
|
70
|
+
onConnect={(provider, address) => {}} // optional
|
|
71
|
+
onAddressChange={(newAddress) => {}} // optional — Xverse account switching
|
|
72
|
+
onDisconnect={() => {}} // optional
|
|
73
|
+
>
|
|
74
|
+
{children}
|
|
75
|
+
</StacksWalletProvider>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### `useConnect()`
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const { connect, connectors, isPending } = useConnect();
|
|
82
|
+
|
|
83
|
+
// connectors = ['xverse', 'leather', 'okx', 'asigna', 'fordefi', 'wallet-connect']
|
|
84
|
+
await connect('xverse');
|
|
85
|
+
await connect('leather', {
|
|
86
|
+
onSuccess: (address, provider) => {},
|
|
87
|
+
onError: (error) => {},
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### `useDisconnect()`
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const { disconnect } = useDisconnect();
|
|
95
|
+
|
|
96
|
+
disconnect();
|
|
97
|
+
disconnect(() => { /* callback after disconnect */ });
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### `useAddress()`
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
const { address, isConnected, isConnecting, isDisconnected, provider } = useAddress();
|
|
104
|
+
|
|
105
|
+
if (isConnected) {
|
|
106
|
+
console.log(address); // 'SP...' or 'ST...'
|
|
107
|
+
console.log(provider); // 'xverse' | 'leather' | ...
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### `useSignMessage()`
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
const { signMessage, signMessageAsync, data, error, isPending } = useSignMessage();
|
|
115
|
+
|
|
116
|
+
// Callback style
|
|
117
|
+
signMessage({ message: 'Hello Stacks' }, {
|
|
118
|
+
onSuccess: ({ publicKey, signature }) => {},
|
|
119
|
+
onError: (error) => {},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Async style
|
|
123
|
+
const { publicKey, signature } = await signMessageAsync({ message: 'Hello Stacks' });
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### `useWriteContract()`
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { Pc, PostConditionMode } from '@stacks/transactions';
|
|
130
|
+
|
|
131
|
+
const { writeContract, writeContractAsync, data, error, isPending } = useWriteContract();
|
|
132
|
+
|
|
133
|
+
writeContract({
|
|
134
|
+
address: 'SP...',
|
|
135
|
+
contract: 'my-contract',
|
|
136
|
+
functionName: 'my-function',
|
|
137
|
+
args: [uintCV(100)],
|
|
138
|
+
pc: {
|
|
139
|
+
postConditions: [Pc.principal('SP...').willSendLte(100n).ustx()],
|
|
140
|
+
mode: PostConditionMode.Deny,
|
|
141
|
+
},
|
|
142
|
+
}, {
|
|
143
|
+
onSuccess: (txHash) => {},
|
|
144
|
+
onError: (error) => {},
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### `useBnsName()`
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
const { bnsName, isLoading } = useBnsName(address);
|
|
152
|
+
// bnsName = 'satoshi.btc' | null
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Utilities
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { getNetworkFromAddress, getStacksWallets, getLocalStorageWallet } from '@satoshai/kit';
|
|
159
|
+
|
|
160
|
+
getNetworkFromAddress('SP...'); // 'mainnet'
|
|
161
|
+
getNetworkFromAddress('ST...'); // 'testnet'
|
|
162
|
+
|
|
163
|
+
const { supported, installed } = getStacksWallets();
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Supported Wallets
|
|
167
|
+
|
|
168
|
+
| Wallet | ID |
|
|
169
|
+
|---|---|
|
|
170
|
+
| Xverse | `xverse` |
|
|
171
|
+
| Leather | `leather` |
|
|
172
|
+
| OKX | `okx` |
|
|
173
|
+
| Asigna | `asigna` |
|
|
174
|
+
| Fordefi | `fordefi` |
|
|
175
|
+
| WalletConnect | `wallet-connect` |
|
|
176
|
+
|
|
177
|
+
## Peer Dependencies
|
|
178
|
+
|
|
179
|
+
- `react` ^18 or ^19
|
|
180
|
+
- `react-dom` ^18 or ^19
|
|
181
|
+
- `@stacks/transactions` >=7.0.0
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@satoshai/kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Typesafe Stacks wallet & contract interaction library for React",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,6 +22,15 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"dev": "tsup --watch",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:unit": "vitest run",
|
|
30
|
+
"test:watch": "vitest",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"clean": "rm -rf dist"
|
|
33
|
+
},
|
|
25
34
|
"dependencies": {
|
|
26
35
|
"@stacks/connect": "^8.2.2",
|
|
27
36
|
"bns-v2-sdk": "^2.1.0"
|
|
@@ -55,14 +64,5 @@
|
|
|
55
64
|
"repository": {
|
|
56
65
|
"type": "git",
|
|
57
66
|
"url": "https://github.com/satoshai-dev/kit"
|
|
58
|
-
},
|
|
59
|
-
"scripts": {
|
|
60
|
-
"build": "tsup",
|
|
61
|
-
"dev": "tsup --watch",
|
|
62
|
-
"test": "vitest run",
|
|
63
|
-
"test:unit": "vitest run",
|
|
64
|
-
"test:watch": "vitest",
|
|
65
|
-
"typecheck": "tsc --noEmit",
|
|
66
|
-
"clean": "rm -rf dist"
|
|
67
67
|
}
|
|
68
|
-
}
|
|
68
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Joao Faustino
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|