@nexus-cross/crossx-sdk-wagmi 2.0.2-beta.1 → 2.0.2-beta.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/README.md +250 -0
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# @nexus-cross/crossx-sdk-wagmi
|
|
2
|
+
|
|
3
|
+
[wagmi](https://wagmi.sh/) connector for the CROSSx Embedded Wallet — use standard wagmi hooks (`useAccount`, `useConnect`, `useSendTransaction`, etc.) with CROSSx OAuth-based wallet.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @nexus-cross/crossx-sdk-wagmi @nexus-cross/crossx-sdk-core
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @nexus-cross/crossx-sdk-wagmi @nexus-cross/crossx-sdk-core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Peer dependencies:** `wagmi >=2.0.0`, `viem >=2.0.0`
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
### Simple Mode
|
|
18
|
+
|
|
19
|
+
Pass SDK config directly — the connector creates the SDK instance internally.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { createConfig, http } from 'wagmi';
|
|
23
|
+
import { crossxConnector } from '@nexus-cross/crossx-sdk-wagmi';
|
|
24
|
+
import type { Chain } from 'viem';
|
|
25
|
+
|
|
26
|
+
const crossMainnet = {
|
|
27
|
+
id: 612055,
|
|
28
|
+
name: 'CROSS Mainnet',
|
|
29
|
+
nativeCurrency: { name: 'CROSS', symbol: 'CROSS', decimals: 18 },
|
|
30
|
+
rpcUrls: { default: { http: ['https://rpc.crossmainnet.io'] } },
|
|
31
|
+
} as const satisfies Chain;
|
|
32
|
+
|
|
33
|
+
const config = createConfig({
|
|
34
|
+
chains: [crossMainnet],
|
|
35
|
+
connectors: [
|
|
36
|
+
crossxConnector({
|
|
37
|
+
projectId: 'your-project-id',
|
|
38
|
+
appName: 'My DApp',
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
transports: {
|
|
42
|
+
[crossMainnet.id]: http(),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Advanced Mode
|
|
48
|
+
|
|
49
|
+
Create the SDK yourself for full control over configuration, then inject it.
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { createConfig, http } from 'wagmi';
|
|
53
|
+
import { createCROSSxSDK, ChainId } from '@nexus-cross/crossx-sdk-core';
|
|
54
|
+
import { createCROSSxConnector } from '@nexus-cross/crossx-sdk-wagmi';
|
|
55
|
+
|
|
56
|
+
const sdk = createCROSSxSDK({
|
|
57
|
+
projectId: 'your-project-id',
|
|
58
|
+
appName: 'My DApp',
|
|
59
|
+
theme: 'dark',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const config = createConfig({
|
|
63
|
+
chains: [crossMainnet],
|
|
64
|
+
connectors: [
|
|
65
|
+
createCROSSxConnector({
|
|
66
|
+
sdk,
|
|
67
|
+
defaultChainId: ChainId.CROSS_MAINNET,
|
|
68
|
+
}),
|
|
69
|
+
],
|
|
70
|
+
transports: {
|
|
71
|
+
[crossMainnet.id]: http(),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Use with React
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
import { WagmiProvider } from 'wagmi';
|
|
80
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
81
|
+
import { useAccount, useConnect, useDisconnect, useSendTransaction } from 'wagmi';
|
|
82
|
+
|
|
83
|
+
const queryClient = new QueryClient();
|
|
84
|
+
|
|
85
|
+
function App() {
|
|
86
|
+
return (
|
|
87
|
+
<WagmiProvider config={config}>
|
|
88
|
+
<QueryClientProvider client={queryClient}>
|
|
89
|
+
<Wallet />
|
|
90
|
+
</QueryClientProvider>
|
|
91
|
+
</WagmiProvider>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function Wallet() {
|
|
96
|
+
const { address, isConnected } = useAccount();
|
|
97
|
+
const { connect, connectors } = useConnect();
|
|
98
|
+
const { disconnect } = useDisconnect();
|
|
99
|
+
const { sendTransaction } = useSendTransaction();
|
|
100
|
+
|
|
101
|
+
if (isConnected) {
|
|
102
|
+
return (
|
|
103
|
+
<div>
|
|
104
|
+
<p>Connected: {address}</p>
|
|
105
|
+
<button onClick={() => disconnect()}>Disconnect</button>
|
|
106
|
+
<button onClick={() => sendTransaction({
|
|
107
|
+
to: '0x...',
|
|
108
|
+
value: 10000000000000000n, // 0.01 CROSS
|
|
109
|
+
})}>
|
|
110
|
+
Send
|
|
111
|
+
</button>
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<button onClick={() => connect({ connector: connectors[0] })}>
|
|
118
|
+
Connect CROSSx
|
|
119
|
+
</button>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## API Reference
|
|
127
|
+
|
|
128
|
+
### `crossxConnector(options)` — Simple Mode
|
|
129
|
+
|
|
130
|
+
Creates a wagmi connector with automatic SDK creation.
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
crossxConnector({
|
|
134
|
+
// SDKConfig fields
|
|
135
|
+
projectId: 'your-project-id', // Required
|
|
136
|
+
appName: 'My DApp', // Required
|
|
137
|
+
theme: 'light',
|
|
138
|
+
themeTokens: { /* ... */ },
|
|
139
|
+
locale: 'en',
|
|
140
|
+
|
|
141
|
+
// Connector options
|
|
142
|
+
defaultChainId: 'eip155:612055',
|
|
143
|
+
getStoredWalletIndex: () => number,
|
|
144
|
+
onWalletIndexChanged: (index: number) => void,
|
|
145
|
+
getStoredWalletAddress: () => string | null,
|
|
146
|
+
onWalletAddressChanged: (address: string) => void,
|
|
147
|
+
openConnectOtherWallet: () => void,
|
|
148
|
+
})
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### `createCROSSxConnector(options)` — Advanced Mode
|
|
152
|
+
|
|
153
|
+
Creates a wagmi connector with an existing SDK instance.
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
createCROSSxConnector({
|
|
157
|
+
sdk: CROSSxSDK, // Required — pre-created SDK instance
|
|
158
|
+
defaultChainId: 'eip155:612055', // Default chain (CROSS Mainnet)
|
|
159
|
+
getStoredWalletIndex: () => number,
|
|
160
|
+
onWalletIndexChanged: (index: number) => void,
|
|
161
|
+
getStoredWalletAddress: () => string | null,
|
|
162
|
+
onWalletAddressChanged: (address: string) => void,
|
|
163
|
+
openConnectOtherWallet: () => void,
|
|
164
|
+
})
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Options
|
|
170
|
+
|
|
171
|
+
### Common Options
|
|
172
|
+
|
|
173
|
+
| Option | Type | Default | Description |
|
|
174
|
+
|--------|------|---------|-------------|
|
|
175
|
+
| `defaultChainId` | `string \| number` | `'eip155:612055'` | Default chain ID (CAIP-2 or numeric) |
|
|
176
|
+
| `getStoredWalletIndex` | `() => number` | localStorage | Callback to retrieve persisted wallet index |
|
|
177
|
+
| `onWalletIndexChanged` | `(index) => void` | localStorage | Callback when active wallet index changes |
|
|
178
|
+
| `getStoredWalletAddress` | `() => string \| null` | localStorage | Callback to retrieve persisted wallet address |
|
|
179
|
+
| `onWalletAddressChanged` | `(address) => void` | localStorage | Callback when active wallet address changes |
|
|
180
|
+
| `openConnectOtherWallet` | `() => void` | — | Called when user clicks an external wallet row in the login modal |
|
|
181
|
+
|
|
182
|
+
By default, the connector uses `localStorage` for wallet index/address persistence. Override with custom callbacks for alternative storage (e.g., cookies, state management).
|
|
183
|
+
|
|
184
|
+
### External Wallet Integration
|
|
185
|
+
|
|
186
|
+
When `openConnectOtherWallet` is provided, the SDK login modal shows external wallet options (Binance, MetaMask, CROSSx). Clicking a row triggers this callback, where you can open your own connect modal.
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
crossxConnector({
|
|
190
|
+
projectId: '...',
|
|
191
|
+
appName: 'MyDApp',
|
|
192
|
+
openConnectOtherWallet: () => {
|
|
193
|
+
// Open your wagmi/RainbowKit/Web3Modal connect dialog
|
|
194
|
+
openConnectModal();
|
|
195
|
+
},
|
|
196
|
+
})
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
To show only specific wallets, use `connectOtherWallets`:
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
crossxConnector({
|
|
203
|
+
projectId: '...',
|
|
204
|
+
appName: 'MyDApp',
|
|
205
|
+
connectOtherWallets: ['metamask', 'binance'],
|
|
206
|
+
openConnectOtherWallet: () => openConnectModal(),
|
|
207
|
+
})
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Connector Behavior
|
|
213
|
+
|
|
214
|
+
| Feature | Behavior |
|
|
215
|
+
|---------|----------|
|
|
216
|
+
| `connect()` | Opens OAuth sign-in → creates/restores wallet → returns accounts |
|
|
217
|
+
| `disconnect()` | Calls `sdk.signOut()` → clears stored wallet data |
|
|
218
|
+
| `switchChain()` | Updates internal chain ID, emits `change` event |
|
|
219
|
+
| `isAuthorized()` | Waits for SDK ready, then checks `sdk.isAuthenticated()` |
|
|
220
|
+
| Auto-sync | Listens to SDK `authChanged` / `addressChanged` events |
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## Exports
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
// Connectors
|
|
228
|
+
export { crossxConnector } from '@nexus-cross/crossx-sdk-wagmi';
|
|
229
|
+
export { createCROSSxConnector } from '@nexus-cross/crossx-sdk-wagmi';
|
|
230
|
+
|
|
231
|
+
// EIP-1193 Provider (advanced use)
|
|
232
|
+
export { CROSSxEIP1193Provider } from '@nexus-cross/crossx-sdk-wagmi';
|
|
233
|
+
|
|
234
|
+
// Types
|
|
235
|
+
export type { CrossxConnectorOptions } from '@nexus-cross/crossx-sdk-wagmi';
|
|
236
|
+
export type { CROSSxConnectorOptions } from '@nexus-cross/crossx-sdk-wagmi';
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Related Packages
|
|
242
|
+
|
|
243
|
+
| Package | Description |
|
|
244
|
+
|---------|-------------|
|
|
245
|
+
| [`@nexus-cross/crossx-sdk-core`](https://www.npmjs.com/package/@nexus-cross/crossx-sdk-core) | Core SDK (vanilla JS) |
|
|
246
|
+
| [`@nexus-cross/crossx-sdk-react`](https://www.npmjs.com/package/@nexus-cross/crossx-sdk-react) | React hooks (without wagmi) |
|
|
247
|
+
|
|
248
|
+
## License
|
|
249
|
+
|
|
250
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexus-cross/crossx-sdk-wagmi",
|
|
3
|
-
"version": "2.0.2-beta.
|
|
3
|
+
"version": "2.0.2-beta.3",
|
|
4
4
|
"description": "CROSSx SDK wagmi Connector — OAuth 임베디드 지갑을 wagmi에 통합",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -17,9 +17,10 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@nexus-cross/crossx-sdk-core": "2.0.2-beta.
|
|
20
|
+
"@nexus-cross/crossx-sdk-core": "^2.0.2-beta.3"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
+
"@nexus-cross/crossx-sdk-core": "^2.0.0",
|
|
23
24
|
"viem": ">=2.0.0",
|
|
24
25
|
"wagmi": ">=2.0.0"
|
|
25
26
|
},
|