@walletconnect/cli-sdk 0.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.
- package/README.md +131 -0
- package/dist/cli.js +680 -0
- package/dist/index.cjs +108 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +146 -0
- package/dist/index.d.ts +146 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# @walletconnect/cli-sdk
|
|
2
|
+
|
|
3
|
+
Wallet connection and transaction signing for CLI applications, powered by the WalletConnect protocol.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { WalletConnectCLI } from "@walletconnect/cli-sdk";
|
|
9
|
+
|
|
10
|
+
const wc = new WalletConnectCLI({
|
|
11
|
+
projectId: "your-walletconnect-cloud-project-id",
|
|
12
|
+
metadata: {
|
|
13
|
+
name: "My CLI Tool",
|
|
14
|
+
description: "A command-line DeFi tool",
|
|
15
|
+
url: "https://example.com",
|
|
16
|
+
icons: [],
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Connect — shows QR in terminal (instant if session exists)
|
|
21
|
+
const { accounts } = await wc.connect();
|
|
22
|
+
const address = accounts[0].split(":")[2];
|
|
23
|
+
|
|
24
|
+
// Request signature
|
|
25
|
+
const txHash = await wc.request({
|
|
26
|
+
chainId: "eip155:1",
|
|
27
|
+
request: {
|
|
28
|
+
method: "eth_sendTransaction",
|
|
29
|
+
params: [{ from: address, to: "0x...", value: "0x0", data: "0x..." }],
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Disconnect when done
|
|
34
|
+
await wc.disconnect();
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## `withWallet` Helper
|
|
38
|
+
|
|
39
|
+
For the common connect → do work → cleanup pattern:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { withWallet } from "@walletconnect/cli-sdk";
|
|
43
|
+
|
|
44
|
+
await withWallet({ projectId: "...", metadata: { ... } }, async (wallet, { accounts }) => {
|
|
45
|
+
const address = accounts[0].split(":")[2];
|
|
46
|
+
const txHash = await wallet.request({
|
|
47
|
+
chainId: "eip155:1",
|
|
48
|
+
request: {
|
|
49
|
+
method: "eth_sendTransaction",
|
|
50
|
+
params: [{ from: address, to: "0x...", value: "0x0" }],
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
console.log("TX:", txHash);
|
|
54
|
+
});
|
|
55
|
+
// Automatically disconnects and cleans up
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Configuration
|
|
59
|
+
|
|
60
|
+
| Option | Type | Default | Description |
|
|
61
|
+
|--------|------|---------|-------------|
|
|
62
|
+
| `projectId` | `string` | **required** | WalletConnect Cloud project ID |
|
|
63
|
+
| `metadata` | `Metadata` | **required** | App metadata (name, description, url, icons) |
|
|
64
|
+
| `chains` | `string[]` | `['eip155:1']` | CAIP-2 chain IDs to request |
|
|
65
|
+
| `methods` | `string[]` | EVM defaults | JSON-RPC methods to request |
|
|
66
|
+
| `events` | `string[]` | `['chainChanged', 'accountsChanged']` | Events to subscribe to |
|
|
67
|
+
| `ui` | `'terminal' \| 'browser'` | `'terminal'` | Connection UI mode |
|
|
68
|
+
| `port` | `number` | auto | Port for browser UI server |
|
|
69
|
+
| `storagePath` | `string` | `~/.walletconnect-cli/` | Session storage directory |
|
|
70
|
+
| `autoConnect` | `boolean` | `true` | Auto-restore previous session |
|
|
71
|
+
| `logger` | `'info' \| 'debug' \| 'silent'` | `'silent'` | Log verbosity |
|
|
72
|
+
|
|
73
|
+
## Browser UI Mode
|
|
74
|
+
|
|
75
|
+
For a richer connection experience, use browser mode:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const wc = new WalletConnectCLI({
|
|
79
|
+
projectId: "...",
|
|
80
|
+
metadata: { ... },
|
|
81
|
+
ui: "browser",
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Opens http://localhost:<port> with styled QR code
|
|
85
|
+
const { accounts } = await wc.connect();
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The browser page displays a QR code, updates via SSE when connected, and auto-closes.
|
|
89
|
+
|
|
90
|
+
## Events
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
wc.on("connect", ({ session, accounts, topic }) => { ... });
|
|
94
|
+
wc.on("disconnect", () => { ... });
|
|
95
|
+
wc.on("session_update", (session) => { ... });
|
|
96
|
+
wc.on("session_delete", ({ topic }) => { ... });
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## API
|
|
100
|
+
|
|
101
|
+
### `new WalletConnectCLI(options)`
|
|
102
|
+
|
|
103
|
+
Creates a new CLI SDK instance. No async work happens in the constructor.
|
|
104
|
+
|
|
105
|
+
### `wc.connect(options?): Promise<ConnectResult>`
|
|
106
|
+
|
|
107
|
+
Connects to a wallet. If a valid session exists, returns immediately. Otherwise displays QR code and waits for wallet approval.
|
|
108
|
+
|
|
109
|
+
### `wc.request<T>(options): Promise<T>`
|
|
110
|
+
|
|
111
|
+
Sends a JSON-RPC request to the connected wallet.
|
|
112
|
+
|
|
113
|
+
### `wc.disconnect(): Promise<void>`
|
|
114
|
+
|
|
115
|
+
Disconnects the current session. Silently succeeds if no session is active.
|
|
116
|
+
|
|
117
|
+
### `wc.isConnected(): boolean`
|
|
118
|
+
|
|
119
|
+
Returns whether a valid session is active.
|
|
120
|
+
|
|
121
|
+
### `wc.getAccounts(): string[]`
|
|
122
|
+
|
|
123
|
+
Returns CAIP-10 account IDs from the current session.
|
|
124
|
+
|
|
125
|
+
### `wc.getSession(): SessionTypes.Struct | null`
|
|
126
|
+
|
|
127
|
+
Returns the raw session object.
|
|
128
|
+
|
|
129
|
+
### `wc.destroy(): Promise<void>`
|
|
130
|
+
|
|
131
|
+
Cleans up all resources (browser server, listeners, client references).
|