@nexus-cross/crossx-sdk-core 2.0.2-beta.2 → 2.0.2
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 +225 -196
- package/dist/adapters/confirmation/BrowserConfirmationAdapter.d.ts.map +1 -1
- package/dist/crossx.global +36 -36
- package/dist/index.cjs +46 -46
- package/dist/index.js +235 -222
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
# @nexus-cross/crossx-sdk-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
OAuth-based Embedded Wallet SDK for JavaScript/TypeScript.
|
|
4
|
+
|
|
5
|
+
Built on **Clean Architecture + Hexagonal Architecture** — environment-independent business logic with replaceable adapters.
|
|
4
6
|
|
|
5
7
|
## Features
|
|
6
8
|
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
- **CAIP-2
|
|
12
|
-
- **
|
|
9
|
+
- **OAuth Sign-In** — Google & Apple social login with automatic session management
|
|
10
|
+
- **Embedded Wallet** — Server-managed HD wallet with client-side PIN protection
|
|
11
|
+
- **EIP-1193 Provider** — Drop-in integration with ethers.js, viem, and wagmi
|
|
12
|
+
- **Transaction Confirmation** — Built-in approval modal before every sign/send (cannot be bypassed)
|
|
13
|
+
- **Multi-Chain** — CAIP-2 standard chain IDs (`eip155:612055`)
|
|
14
|
+
- **Multi-Wallet** — Multiple addresses per account with wallet selector UI
|
|
15
|
+
- **Theme Customization** — Light/dark mode with granular color token overrides
|
|
13
16
|
|
|
14
17
|
## Installation
|
|
15
18
|
|
|
16
19
|
```bash
|
|
17
20
|
npm install @nexus-cross/crossx-sdk-core
|
|
21
|
+
# or
|
|
22
|
+
pnpm add @nexus-cross/crossx-sdk-core
|
|
23
|
+
# or
|
|
24
|
+
yarn add @nexus-cross/crossx-sdk-core
|
|
18
25
|
```
|
|
19
26
|
|
|
20
27
|
## Quick Start
|
|
@@ -23,216 +30,215 @@ npm install @nexus-cross/crossx-sdk-core
|
|
|
23
30
|
import { createCROSSxSDK, ChainId } from '@nexus-cross/crossx-sdk-core';
|
|
24
31
|
|
|
25
32
|
const sdk = createCROSSxSDK({
|
|
26
|
-
|
|
33
|
+
projectId: 'your-project-id',
|
|
34
|
+
appName: 'My DApp',
|
|
35
|
+
theme: 'light',
|
|
27
36
|
});
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
// Restore previous session (if any)
|
|
39
|
+
const session = await sdk.initialize();
|
|
40
|
+
if (session) {
|
|
41
|
+
console.log('Restored:', session.address);
|
|
42
|
+
}
|
|
33
43
|
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
// Sign in with OAuth
|
|
45
|
+
await sdk.signIn({ provider: 'google' });
|
|
36
46
|
|
|
37
|
-
|
|
47
|
+
// Get wallet address
|
|
48
|
+
const addr = await sdk.getAddress();
|
|
49
|
+
console.log(addr?.address);
|
|
50
|
+
|
|
51
|
+
// Sign a message (confirmation modal is shown automatically)
|
|
52
|
+
const { signature } = await sdk.signMessage(
|
|
53
|
+
ChainId.CROSS_MAINNET,
|
|
54
|
+
'Hello CROSSx!',
|
|
55
|
+
);
|
|
56
|
+
```
|
|
38
57
|
|
|
39
58
|
## API Reference
|
|
40
59
|
|
|
41
60
|
### Initialization & Authentication
|
|
42
61
|
|
|
43
62
|
```ts
|
|
44
|
-
// Initialize SDK
|
|
45
|
-
await sdk.
|
|
63
|
+
// Initialize SDK — restores session if available
|
|
64
|
+
const session = await sdk.initialize();
|
|
46
65
|
|
|
47
|
-
// Sign in (OAuth popup)
|
|
66
|
+
// Sign in (opens OAuth popup)
|
|
48
67
|
const result = await sdk.signIn();
|
|
49
68
|
const result = await sdk.signIn({ provider: 'google' });
|
|
50
69
|
|
|
70
|
+
// Sign in + auto-create wallet if none exists
|
|
71
|
+
const result = await sdk.signInWithCreate();
|
|
72
|
+
|
|
51
73
|
// Check authentication status
|
|
52
|
-
sdk.isAuthenticated();
|
|
53
|
-
sdk.
|
|
74
|
+
sdk.isAuthenticated(); // boolean
|
|
75
|
+
sdk.currentAddress; // string | null
|
|
76
|
+
|
|
77
|
+
// Validate session (returns boolean, never throws)
|
|
78
|
+
const valid = await sdk.ensureLoggedIn();
|
|
54
79
|
|
|
55
80
|
// Sign out
|
|
56
81
|
await sdk.signOut();
|
|
57
82
|
```
|
|
58
83
|
|
|
59
|
-
|
|
84
|
+
### User Info
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
const info = await sdk.getUserInfo();
|
|
88
|
+
// { id, email?, loginType?, addresses }
|
|
89
|
+
```
|
|
60
90
|
|
|
61
91
|
### Wallet
|
|
62
92
|
|
|
63
93
|
```ts
|
|
64
|
-
// Create wallet (when
|
|
94
|
+
// Create wallet (when none exists after sign-in)
|
|
65
95
|
const { address } = await sdk.createWallet();
|
|
66
96
|
|
|
67
|
-
// Get
|
|
68
|
-
const
|
|
69
|
-
|
|
97
|
+
// Get active wallet address
|
|
98
|
+
const addr = await sdk.getAddress(); // { address, index } | null
|
|
99
|
+
const addr = await sdk.getAddress(1); // specific index
|
|
70
100
|
|
|
71
|
-
//
|
|
72
|
-
const
|
|
73
|
-
```
|
|
101
|
+
// List all wallet addresses
|
|
102
|
+
const addrs = await sdk.getAddresses(); // [{ address, index, name? }]
|
|
74
103
|
|
|
75
|
-
|
|
104
|
+
// Open wallet selector modal (multi-wallet)
|
|
105
|
+
const selected = await sdk.selectWallet();
|
|
76
106
|
|
|
77
|
-
|
|
107
|
+
// Native balance
|
|
108
|
+
const { wei, formatted } = await sdk.getBalance(ChainId.CROSS_MAINNET);
|
|
109
|
+
console.log(formatted); // "1.234567 CROSS"
|
|
78
110
|
|
|
79
|
-
|
|
111
|
+
// Nonce
|
|
112
|
+
const nonce = await sdk.getNonce(ChainId.CROSS_MAINNET);
|
|
113
|
+
```
|
|
80
114
|
|
|
81
|
-
|
|
82
|
-
import { CROSSxError, ErrorCode } from '@nexus-cross/crossx-sdk-core';
|
|
115
|
+
### Signing
|
|
83
116
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
if (error instanceof CROSSxError && error.code === ErrorCode.USER_REJECTED) {
|
|
88
|
-
console.log('User cancelled the transaction');
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
```
|
|
117
|
+
```ts
|
|
118
|
+
// EIP-191 personal_sign
|
|
119
|
+
const { signature } = await sdk.signMessage('eip155:612055', 'Hello!');
|
|
92
120
|
|
|
93
|
-
|
|
121
|
+
// EIP-712 Typed Data
|
|
122
|
+
const { signature } = await sdk.signTypedData('eip155:612055', typedData);
|
|
94
123
|
|
|
95
|
-
|
|
124
|
+
// Sign transaction (without broadcasting)
|
|
125
|
+
const { signedTx, txHash } = await sdk.signTransaction('eip155:612055', tx);
|
|
126
|
+
```
|
|
96
127
|
|
|
97
|
-
###
|
|
128
|
+
### Sending Transactions
|
|
98
129
|
|
|
99
130
|
```ts
|
|
100
131
|
const tx = {
|
|
101
|
-
from:
|
|
102
|
-
to:
|
|
103
|
-
value:
|
|
104
|
-
data:
|
|
105
|
-
chainId: 612044,
|
|
106
|
-
gasLimit: '0x5208',
|
|
107
|
-
maxFeePerGas: '0x77359400',
|
|
108
|
-
maxPriorityFeePerGas: '0x3b9aca00',
|
|
109
|
-
nonce: await sdk.getNonce('eip155:612044'),
|
|
132
|
+
from: sdk.currentAddress!,
|
|
133
|
+
to: '0x...',
|
|
134
|
+
value: '0x2386f26fc10000', // hex wei
|
|
135
|
+
data: '0x',
|
|
110
136
|
};
|
|
111
137
|
|
|
112
|
-
//
|
|
113
|
-
const {
|
|
114
|
-
|
|
115
|
-
// Send (returns immediately with status: 'pending')
|
|
116
|
-
const { txHash } = await sdk.sendTransaction('eip155:612044', tx);
|
|
138
|
+
// Send (returns immediately)
|
|
139
|
+
const { txHash } = await sdk.sendTransaction('eip155:612055', tx);
|
|
117
140
|
|
|
118
|
-
// Send +
|
|
119
|
-
const { txHash, receipt } = await sdk.
|
|
120
|
-
|
|
141
|
+
// Send + wait for receipt
|
|
142
|
+
const { txHash, receipt } = await sdk.sendTransactionWithWaitForReceipt(
|
|
143
|
+
'eip155:612055',
|
|
144
|
+
tx,
|
|
145
|
+
);
|
|
146
|
+
console.log(receipt.status); // '0x1' = success
|
|
121
147
|
```
|
|
122
148
|
|
|
123
|
-
|
|
149
|
+
### Transaction Confirmation Modal
|
|
124
150
|
|
|
125
|
-
|
|
151
|
+
Every `signTransaction`, `sendTransaction`, and `signMessage` call automatically displays a user approval modal. There is no API to bypass it.
|
|
126
152
|
|
|
127
153
|
```ts
|
|
128
|
-
|
|
129
|
-
const receipt = await sdk.getTransactionReceipt(txHash, 'eip155:612044');
|
|
154
|
+
import { CROSSxError, ErrorCode } from '@nexus-cross/crossx-sdk-core';
|
|
130
155
|
|
|
131
|
-
|
|
132
|
-
|
|
156
|
+
try {
|
|
157
|
+
await sdk.sendTransaction(ChainId.CROSS_MAINNET, tx);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (error instanceof CROSSxError && error.code === ErrorCode.USER_REJECTED) {
|
|
160
|
+
console.log('User cancelled');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
133
164
|
|
|
134
|
-
|
|
135
|
-
|
|
165
|
+
### Receipt Polling
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
// Single query (null if not yet mined)
|
|
169
|
+
const receipt = await sdk.getTransactionReceipt(txHash, 'eip155:612055');
|
|
170
|
+
|
|
171
|
+
// Poll until mined
|
|
172
|
+
const receipt = await sdk.waitForTxAndGetReceipt(txHash, 'eip155:612055', {
|
|
136
173
|
intervalMs: 3000,
|
|
137
|
-
timeoutMs:
|
|
174
|
+
timeoutMs: 120000,
|
|
138
175
|
});
|
|
139
176
|
```
|
|
140
177
|
|
|
141
|
-
---
|
|
142
|
-
|
|
143
178
|
### EIP-1193 Provider
|
|
144
179
|
|
|
145
|
-
Standard
|
|
180
|
+
Standard provider for direct integration with ethers.js, viem, etc.
|
|
146
181
|
|
|
147
182
|
```ts
|
|
148
|
-
const provider = sdk.getProvider('eip155:
|
|
183
|
+
const provider = sdk.getProvider('eip155:612055');
|
|
149
184
|
|
|
150
|
-
// ethers.js
|
|
151
|
-
import {
|
|
152
|
-
const ethersProvider = new
|
|
185
|
+
// ethers.js v6
|
|
186
|
+
import { BrowserProvider } from 'ethers';
|
|
187
|
+
const ethersProvider = new BrowserProvider(provider);
|
|
153
188
|
const signer = await ethersProvider.getSigner();
|
|
154
|
-
await signer.sendTransaction({ to: '0x...', value: ethers.parseEther('0.01') });
|
|
155
189
|
|
|
156
190
|
// viem
|
|
157
191
|
import { createWalletClient, custom } from 'viem';
|
|
158
192
|
const client = createWalletClient({ transport: custom(provider) });
|
|
159
193
|
```
|
|
160
194
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
### Generic RPC Calls
|
|
164
|
-
|
|
165
|
-
Sends JSON-RPC requests directly to the node via the `/wallet/rpc` endpoint.
|
|
195
|
+
### Generic JSON-RPC
|
|
166
196
|
|
|
167
197
|
```ts
|
|
168
|
-
//
|
|
169
|
-
const balance = await sdk.walletRpc(
|
|
198
|
+
// eth_getBalance
|
|
199
|
+
const balance = await sdk.walletRpc(
|
|
200
|
+
'eth_getBalance',
|
|
201
|
+
[address, 'latest'],
|
|
202
|
+
'eip155:612055',
|
|
203
|
+
);
|
|
170
204
|
|
|
171
|
-
// eth_call
|
|
172
|
-
const
|
|
173
|
-
const padded = address.slice(2).padStart(64, '0');
|
|
205
|
+
// eth_call (ERC-20 balanceOf)
|
|
206
|
+
const data = '0x70a08231' + address.slice(2).padStart(64, '0');
|
|
174
207
|
const raw = await sdk.walletRpc(
|
|
175
208
|
'eth_call',
|
|
176
|
-
[{ to:
|
|
177
|
-
'eip155:
|
|
209
|
+
[{ to: tokenAddress, data }, 'latest'],
|
|
210
|
+
'eip155:612055',
|
|
178
211
|
);
|
|
179
|
-
console.log(BigInt(raw).toString());
|
|
180
|
-
|
|
181
|
-
// Same call via Provider
|
|
182
|
-
const result = await provider.request({
|
|
183
|
-
method: 'eth_call',
|
|
184
|
-
params: [{ to: contractAddress, data: '0x' + selector + padded }, 'latest'],
|
|
185
|
-
});
|
|
186
212
|
```
|
|
187
213
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
## Gateway API Access Control (Project Whitelist)
|
|
191
|
-
|
|
192
|
-
The Gateway API enforces whitelist verification so that only authorized projects can access it.
|
|
193
|
-
Only combinations of **project + origin (web) or app ID (native)** registered in the management console are allowed. Unregistered requests are blocked.
|
|
194
|
-
|
|
195
|
-
### Required Headers
|
|
214
|
+
### Gas Estimation
|
|
196
215
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
| `Origin` | Request origin domain (automatically set by browser) | Required for web |
|
|
203
|
-
| `X-App-Id` | bundle ID or package name | Required for native apps |
|
|
204
|
-
| `X-App-Type` | `ios` / `android` / `windows` | Required when using `X-App-Id` |
|
|
205
|
-
|
|
206
|
-
### Request Examples
|
|
207
|
-
|
|
208
|
-
**Web request** (browser automatically includes `Origin`):
|
|
209
|
-
|
|
210
|
-
```
|
|
211
|
-
X-Project-Id: {project-id}
|
|
212
|
-
Authorization: Bearer {token}
|
|
216
|
+
```ts
|
|
217
|
+
const gasPrice = await sdk.getGasPrice('eip155:612055');
|
|
218
|
+
const gasLimit = await sdk.estimateGas(tx, 'eip155:612055');
|
|
219
|
+
const baseFee = await sdk.getBaseFeePerGas('eip155:612055');
|
|
220
|
+
const priorityFee = await sdk.getMaxPriorityFeePerGas('eip155:612055');
|
|
213
221
|
```
|
|
214
222
|
|
|
215
|
-
|
|
223
|
+
### Events
|
|
216
224
|
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
Authorization: Bearer {token}
|
|
225
|
+
```ts
|
|
226
|
+
sdk.on('authChanged', ({ isAuthenticated, address }) => { /* ... */ });
|
|
227
|
+
sdk.on('addressChanged', ({ address, index }) => { /* ... */ });
|
|
228
|
+
sdk.on('initialized', ({ isAuthenticated }) => { /* ... */ });
|
|
222
229
|
```
|
|
223
230
|
|
|
224
|
-
###
|
|
231
|
+
### Theme
|
|
225
232
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
| `-10023` | Missing `X-Project-Id` header |
|
|
230
|
-
| `-10024` | Missing `Origin` or `X-App-Id` header |
|
|
231
|
-
| `-10025` | `X-App-Type` is not `android` / `ios` / `windows` |
|
|
233
|
+
```ts
|
|
234
|
+
// Runtime theme switch
|
|
235
|
+
sdk.applyTheme('dark');
|
|
232
236
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
237
|
+
// With custom color tokens
|
|
238
|
+
sdk.applyTheme('dark', {
|
|
239
|
+
dark: { primary: '#FF6B35', bg: '#1A0A00' },
|
|
240
|
+
});
|
|
241
|
+
```
|
|
236
242
|
|
|
237
243
|
---
|
|
238
244
|
|
|
@@ -240,78 +246,96 @@ Authorization: Bearer {token}
|
|
|
240
246
|
|
|
241
247
|
```ts
|
|
242
248
|
const sdk = createCROSSxSDK({
|
|
243
|
-
|
|
244
|
-
|
|
249
|
+
// Required
|
|
250
|
+
projectId: 'your-project-id',
|
|
251
|
+
appName: 'My DApp',
|
|
245
252
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
/** Confirmation modal theme: 'light' (default) | 'dark' */
|
|
250
|
-
theme: 'light',
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Confirmation modal color customization (independent overrides per light/dark mode)
|
|
254
|
-
*/
|
|
253
|
+
// Theme
|
|
254
|
+
theme: 'light', // 'light' | 'dark'
|
|
255
|
+
autoDetectTheme: false, // follow OS dark mode
|
|
255
256
|
themeTokens: {
|
|
256
|
-
light: {
|
|
257
|
-
|
|
258
|
-
bg: '#F5F0EB', // Card background color (default: #FFFFFF)
|
|
259
|
-
},
|
|
260
|
-
dark: {
|
|
261
|
-
primary: '#FF6B35',
|
|
262
|
-
bg: '#1A0A00', // Card background color (default: #121212)
|
|
263
|
-
},
|
|
257
|
+
light: { primary: '#FF6B35' }, // per-mode color overrides
|
|
258
|
+
dark: { primary: '#FF6B35', bg: '#1A0A00' },
|
|
264
259
|
},
|
|
265
260
|
|
|
266
|
-
|
|
261
|
+
// Locale
|
|
262
|
+
locale: 'en', // 'en' | 'ko'
|
|
263
|
+
|
|
264
|
+
// Receipt polling defaults
|
|
267
265
|
receiptPolling: {
|
|
268
|
-
intervalMs: 2000,
|
|
269
|
-
timeoutMs: 60000,
|
|
266
|
+
intervalMs: 2000,
|
|
267
|
+
timeoutMs: 60000,
|
|
270
268
|
},
|
|
271
269
|
|
|
272
|
-
|
|
273
|
-
* Enable debug log output (default: true)
|
|
274
|
-
* ⚠️ Always disabled in production builds regardless of this value.
|
|
275
|
-
*/
|
|
270
|
+
// Debug logging (only effective in dev builds)
|
|
276
271
|
debug: true,
|
|
272
|
+
|
|
273
|
+
// Custom logger
|
|
274
|
+
logger: {
|
|
275
|
+
log: (...args) => console.log('[MyApp]', ...args),
|
|
276
|
+
warn: (...args) => console.warn('[MyApp]', ...args),
|
|
277
|
+
error: (...args) => console.error('[MyApp]', ...args),
|
|
278
|
+
},
|
|
277
279
|
});
|
|
278
280
|
```
|
|
279
281
|
|
|
280
|
-
###
|
|
281
|
-
|
|
282
|
-
| Method | Description |
|
|
283
|
-
|---|---|
|
|
284
|
-
| `config.theme` | Initial theme setting (`'light'` by default) |
|
|
285
|
-
| `sdk.setTheme('dark')` | Runtime theme switching (preserves `themeTokens` overrides) |
|
|
286
|
-
| `config.themeTokens.light.*` | Light mode semantic token overrides |
|
|
287
|
-
| `config.themeTokens.dark.*` | Dark mode semantic token overrides |
|
|
282
|
+
### Theme Tokens
|
|
288
283
|
|
|
289
|
-
|
|
284
|
+
Override individual semantic color tokens per mode. Unspecified tokens retain their defaults.
|
|
290
285
|
|
|
291
|
-
|
|
286
|
+
| Token | Description | Default (light) | Default (dark) |
|
|
287
|
+
|-------|-------------|-----------------|----------------|
|
|
288
|
+
| `primary` | Buttons & accent | `#019D92` | `#019D92` |
|
|
289
|
+
| `secondary` | Secondary accent | `#E70077` | `#E70077` |
|
|
290
|
+
| `onPrimary` | Text on primary | `#FFFFFF` | `#FFFFFF` |
|
|
291
|
+
| `bg` | Card background | `#FFFFFF` | `#121212` |
|
|
292
|
+
| `textPrimary` | Primary text | `#121212` | `#FFFFFF` |
|
|
293
|
+
| `textSecondary` | Secondary text | `rgba(18,18,18,0.7)` | `rgba(255,255,255,0.7)` |
|
|
294
|
+
| `textTertiary` | Tertiary text | `rgba(18,18,18,0.5)` | `rgba(255,255,255,0.5)` |
|
|
295
|
+
| `surfaceDefault` | Surface fill | `rgba(18,18,18,0.05)` | `rgba(255,255,255,0.05)` |
|
|
296
|
+
| `borderDefault` | Default border | `rgba(18,18,18,0.05)` | `rgba(255,255,255,0.05)` |
|
|
297
|
+
| `borderSubtle` | Subtle border | `rgba(18,18,18,0.1)` | `rgba(255,255,255,0.1)` |
|
|
292
298
|
|
|
293
299
|
---
|
|
294
300
|
|
|
295
301
|
## Chain ID Constants
|
|
296
302
|
|
|
297
|
-
Use `ChainId` constants to prevent typos.
|
|
298
|
-
|
|
299
303
|
```ts
|
|
300
304
|
import { ChainId } from '@nexus-cross/crossx-sdk-core';
|
|
301
305
|
|
|
302
|
-
|
|
303
|
-
|
|
306
|
+
ChainId.CROSS_MAINNET // 'eip155:612055'
|
|
307
|
+
ChainId.CROSS_TESTNET // 'eip155:612044'
|
|
308
|
+
ChainId.BSC_MAINNET // 'eip155:56'
|
|
309
|
+
ChainId.BSC_TESTNET // 'eip155:97'
|
|
310
|
+
ChainId.RONIN_MAINNET // 'eip155:2020'
|
|
311
|
+
ChainId.RONIN_TESTNET // 'eip155:202601'
|
|
304
312
|
```
|
|
305
313
|
|
|
306
314
|
---
|
|
307
315
|
|
|
308
|
-
##
|
|
316
|
+
## Error Handling
|
|
317
|
+
|
|
318
|
+
```ts
|
|
319
|
+
import { CROSSxError, ErrorCode } from '@nexus-cross/crossx-sdk-core';
|
|
309
320
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
321
|
+
try {
|
|
322
|
+
await sdk.sendTransaction(chainId, tx);
|
|
323
|
+
} catch (error) {
|
|
324
|
+
if (error instanceof CROSSxError) {
|
|
325
|
+
switch (error.code) {
|
|
326
|
+
case ErrorCode.USER_REJECTED:
|
|
327
|
+
// User cancelled confirmation modal
|
|
328
|
+
break;
|
|
329
|
+
case ErrorCode.AUTH_NOT_AUTHENTICATED:
|
|
330
|
+
// Not signed in
|
|
331
|
+
break;
|
|
332
|
+
case ErrorCode.PIN_CANCELLED:
|
|
333
|
+
// User cancelled PIN entry
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
```
|
|
315
339
|
|
|
316
340
|
---
|
|
317
341
|
|
|
@@ -320,28 +344,33 @@ await sdk.getBalance(ChainId.CROSS_MAINNET); // 'eip155:612055'
|
|
|
320
344
|
```ts
|
|
321
345
|
import type {
|
|
322
346
|
SDKConfig,
|
|
323
|
-
|
|
324
|
-
ConfirmationThemeTokens, // Single mode semantic token type
|
|
347
|
+
SDKThemeTokens,
|
|
325
348
|
AuthResult,
|
|
349
|
+
SDKUserInfo,
|
|
326
350
|
EvmTransactionRequest,
|
|
327
|
-
|
|
328
|
-
TransactionWithReceipt,
|
|
329
|
-
|
|
330
|
-
|
|
351
|
+
TransactionReceipt,
|
|
352
|
+
TransactionWithReceipt,
|
|
353
|
+
SignMessageResp,
|
|
354
|
+
SignTxResp,
|
|
355
|
+
SignTypedDataResp,
|
|
356
|
+
SendTxResp,
|
|
357
|
+
SignInOptions,
|
|
358
|
+
SignOptions,
|
|
331
359
|
ChainIdValue,
|
|
360
|
+
ChainInfo,
|
|
361
|
+
SDKEventMap,
|
|
362
|
+
ConfirmationDetails,
|
|
332
363
|
} from '@nexus-cross/crossx-sdk-core';
|
|
333
364
|
```
|
|
334
365
|
|
|
335
366
|
---
|
|
336
367
|
|
|
337
|
-
## Related
|
|
368
|
+
## Related Packages
|
|
338
369
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
- [wagmi Integration Guide](../../doc/wagmi-integration.md)
|
|
344
|
-
- [Architecture](../../doc/architecture.md)
|
|
370
|
+
| Package | Description |
|
|
371
|
+
|---------|-------------|
|
|
372
|
+
| [`@nexus-cross/crossx-sdk-react`](https://www.npmjs.com/package/@nexus-cross/crossx-sdk-react) | React hooks & provider |
|
|
373
|
+
| [`@nexus-cross/crossx-sdk-wagmi`](https://www.npmjs.com/package/@nexus-cross/crossx-sdk-wagmi) | wagmi connector |
|
|
345
374
|
|
|
346
375
|
## License
|
|
347
376
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrowserConfirmationAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/confirmation/BrowserConfirmationAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EAEnB,0BAA0B,EAC1B,yBAAyB,EAG1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAA8B,MAAM,qCAAqC,CAAC;AACzG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"BrowserConfirmationAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/confirmation/BrowserConfirmationAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EAEnB,0BAA0B,EAC1B,yBAAy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