@b3dotfun/sdk 0.0.5-alpha.6 → 0.0.5

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.
Files changed (93) hide show
  1. package/dist/cjs/anyspend/constants/index.js +2 -2
  2. package/dist/cjs/anyspend/react/components/AnySpend.js +2 -2
  3. package/dist/cjs/anyspend/react/components/index.d.ts +5 -7
  4. package/dist/cjs/anyspend/react/components/index.js +11 -15
  5. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +0 -1
  6. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +3 -4
  7. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +0 -10
  8. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +0 -10
  9. package/dist/cjs/anyspend/services/anyspend.d.ts +1 -7
  10. package/dist/cjs/anyspend/services/anyspend.js +2 -3
  11. package/dist/cjs/anyspend/types/order.d.ts +0 -18
  12. package/dist/cjs/anyspend/types/order.js +0 -1
  13. package/dist/cjs/anyspend/types/req-res/createOrder.d.ts +0 -50
  14. package/dist/cjs/anyspend/types/req-res/createOrder.js +0 -1
  15. package/dist/cjs/anyspend/types/req-res/getOrderAndTransactions.d.ts +0 -35
  16. package/dist/cjs/anyspend/types/req-res/getOrderHistory.d.ts +0 -25
  17. package/dist/cjs/global-account/react/hooks/index.d.ts +1 -2
  18. package/dist/cjs/global-account/react/hooks/index.js +1 -3
  19. package/dist/cjs/global-account/react/hooks/useTokenFromUrl.d.ts +1 -5
  20. package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +13 -74
  21. package/dist/cjs/shared/constants/chains/supported.d.ts +3 -13
  22. package/dist/cjs/shared/constants/chains/supported.js +9 -15
  23. package/dist/esm/anyspend/constants/index.js +2 -2
  24. package/dist/esm/anyspend/react/components/AnySpend.js +2 -2
  25. package/dist/esm/anyspend/react/components/index.d.ts +5 -7
  26. package/dist/esm/anyspend/react/components/index.js +5 -7
  27. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +0 -1
  28. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +4 -5
  29. package/dist/esm/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +0 -10
  30. package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +0 -10
  31. package/dist/esm/anyspend/services/anyspend.d.ts +1 -7
  32. package/dist/esm/anyspend/services/anyspend.js +2 -3
  33. package/dist/esm/anyspend/types/order.d.ts +0 -18
  34. package/dist/esm/anyspend/types/order.js +0 -1
  35. package/dist/esm/anyspend/types/req-res/createOrder.d.ts +0 -50
  36. package/dist/esm/anyspend/types/req-res/createOrder.js +0 -1
  37. package/dist/esm/anyspend/types/req-res/getOrderAndTransactions.d.ts +0 -35
  38. package/dist/esm/anyspend/types/req-res/getOrderHistory.d.ts +0 -25
  39. package/dist/esm/global-account/react/hooks/index.d.ts +1 -2
  40. package/dist/esm/global-account/react/hooks/index.js +0 -1
  41. package/dist/esm/global-account/react/hooks/useTokenFromUrl.d.ts +1 -5
  42. package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +13 -73
  43. package/dist/esm/shared/constants/chains/supported.d.ts +3 -13
  44. package/dist/esm/shared/constants/chains/supported.js +8 -13
  45. package/dist/styles/index.css +1 -1
  46. package/dist/types/anyspend/react/components/index.d.ts +5 -7
  47. package/dist/types/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +0 -1
  48. package/dist/types/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +0 -10
  49. package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +0 -10
  50. package/dist/types/anyspend/services/anyspend.d.ts +1 -7
  51. package/dist/types/anyspend/types/order.d.ts +0 -18
  52. package/dist/types/anyspend/types/req-res/createOrder.d.ts +0 -50
  53. package/dist/types/anyspend/types/req-res/getOrderAndTransactions.d.ts +0 -35
  54. package/dist/types/anyspend/types/req-res/getOrderHistory.d.ts +0 -25
  55. package/dist/types/global-account/react/hooks/index.d.ts +1 -2
  56. package/dist/types/global-account/react/hooks/useTokenFromUrl.d.ts +1 -5
  57. package/dist/types/shared/constants/chains/supported.d.ts +3 -13
  58. package/package.json +3 -3
  59. package/src/anyspend/constants/index.ts +4 -2
  60. package/src/anyspend/react/components/AnySpend.tsx +2 -2
  61. package/src/anyspend/react/components/index.ts +5 -7
  62. package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +4 -7
  63. package/src/anyspend/services/anyspend.ts +2 -5
  64. package/src/anyspend/types/order.ts +0 -1
  65. package/src/anyspend/types/req-res/createOrder.ts +0 -1
  66. package/src/global-account/react/hooks/index.ts +1 -2
  67. package/src/global-account/react/hooks/useTokenFromUrl.tsx +13 -95
  68. package/src/shared/constants/chains/supported.ts +8 -23
  69. package/dist/cjs/anyspend/react/components/webview/WebviewOnrampOrderStatus.d.ts +0 -6
  70. package/dist/cjs/anyspend/react/components/webview/WebviewOnrampOrderStatus.js +0 -37
  71. package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.d.ts +0 -12
  72. package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.js +0 -173
  73. package/dist/cjs/global-account/react/hooks/useB3EnsName.d.ts +0 -9
  74. package/dist/cjs/global-account/react/hooks/useB3EnsName.js +0 -39
  75. package/dist/cjs/shared/generated/coingecko-chains.json +0 -1072
  76. package/dist/esm/anyspend/react/components/webview/WebviewOnrampOrderStatus.d.ts +0 -6
  77. package/dist/esm/anyspend/react/components/webview/WebviewOnrampOrderStatus.js +0 -31
  78. package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.d.ts +0 -12
  79. package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.js +0 -167
  80. package/dist/esm/global-account/react/hooks/useB3EnsName.d.ts +0 -9
  81. package/dist/esm/global-account/react/hooks/useB3EnsName.js +0 -32
  82. package/dist/esm/shared/generated/coingecko-chains.json +0 -1072
  83. package/dist/types/anyspend/react/components/webview/WebviewOnrampOrderStatus.d.ts +0 -6
  84. package/dist/types/anyspend/react/components/webview/WebviewOnrampPayment.d.ts +0 -12
  85. package/dist/types/global-account/react/hooks/useB3EnsName.d.ts +0 -9
  86. package/src/anyspend/README.md +0 -626
  87. package/src/anyspend/react/components/webview/WebviewOnrampOrderStatus.tsx +0 -120
  88. package/src/anyspend/react/components/webview/WebviewOnrampPayment.tsx +0 -369
  89. package/src/global-account/react/hooks/useB3EnsName.ts +0 -49
  90. package/src/shared/generated/coingecko-chains.json +0 -1072
  91. /package/dist/cjs/{shared/generated → generated}/chain-networks.json +0 -0
  92. /package/dist/esm/{shared/generated → generated}/chain-networks.json +0 -0
  93. /package/src/{shared/generated → generated}/chain-networks.json +0 -0
@@ -1,6 +0,0 @@
1
- import { Order } from "@b3dotfun/sdk/anyspend";
2
- interface WebviewOnrampOrderStatusProps {
3
- order: Order;
4
- }
5
- export declare function WebviewOnrampOrderStatus({ order }: WebviewOnrampOrderStatusProps): import("react/jsx-runtime").JSX.Element;
6
- export {};
@@ -1,12 +0,0 @@
1
- import { GetQuoteResponse, Token } from "@b3dotfun/sdk/anyspend";
2
- interface WebviewOnrampPaymentProps {
3
- srcAmountOnRamp: string;
4
- recipientAddress?: string;
5
- destinationToken: Token;
6
- partnerId?: string;
7
- anyspendQuote: GetQuoteResponse | undefined;
8
- onPaymentSuccess: (orderId: string) => void;
9
- userId?: string;
10
- }
11
- export declare function WebviewOnrampPayment({ srcAmountOnRamp, recipientAddress, destinationToken, anyspendQuote, onPaymentSuccess, userId, partnerId }: WebviewOnrampPaymentProps): import("react/jsx-runtime").JSX.Element;
12
- export {};
@@ -1,9 +0,0 @@
1
- export declare const useB3EnsName: () => {
2
- registerEns: (username: string, message: string, hash: string) => Promise<{
3
- success: boolean;
4
- error?: string;
5
- }>;
6
- getEns: (address: string) => Promise<{
7
- name: string;
8
- }>;
9
- };
@@ -1,626 +0,0 @@
1
- # AnySpend SDK Documentation
2
-
3
- AnySpend is a powerful cross-chain protocol that enables seamless token swaps, NFT minting, tournament participation, and custom smart contract interactions across multiple blockchain networks. Built for developers who want to provide their users with a frictionless Web3 experience.
4
-
5
- ## 📦 Overview
6
-
7
- AnySpend handles the complexity of cross-chain operations, gas management, and payment processing, allowing users to:
8
-
9
- - **Cross-chain Swaps**: Swap tokens across different blockchain networks
10
- - **NFT Minting**: Mint NFTs with automatic payment handling
11
- - **Custom Interactions**: Execute any smart contract operations (tournaments, staking, gaming, etc.)
12
- - **Fiat Onramp**: Convert fiat currency to crypto using integrated payment providers
13
- - **Gasless Transactions**: Users don't need to worry about gas fees
14
-
15
- ### Key Features
16
-
17
- - **Multi-chain Support**: Works across Ethereum, Base, B3, and other supported networks
18
- - **Payment Flexibility**: Accept payments in various cryptocurrencies or fiat
19
- - **Order Management**: Track transaction status in real-time
20
- - **Error Recovery**: Automatic refund handling for failed transactions
21
- - **React Integration**: Pre-built components for easy integration
22
- - **TypeScript Support**: Full type safety and IntelliSense
23
-
24
- ## 🚀 Getting Started
25
-
26
- ### Prerequisites
27
-
28
- - Node.js v20.15.0+
29
- - React 18/19
30
-
31
- ### Installation
32
-
33
- ```bash
34
- npm install @b3dotfun/sdk
35
- # or
36
- pnpm add @b3dotfun/sdk
37
- ```
38
-
39
- ### Basic Setup
40
-
41
- ```tsx
42
- import { AnySpendProvider } from "@b3dotfun/sdk/anyspend/react";
43
- import "@b3dotfun/sdk/index.css";
44
-
45
- function App() {
46
- return <AnySpendProvider>{/* Your app components */}</AnySpendProvider>;
47
- }
48
- ```
49
-
50
- ### Quick Start Example
51
-
52
- ```tsx
53
- import { AnySpendNFTButton } from "@b3dotfun/sdk/anyspend/react";
54
-
55
- function NFTMinting() {
56
- const nftContract = {
57
- chainId: 8333, // B3 network
58
- contractAddress: "0x9c275ff1634519E9B5449ec79cd939B5F900564d",
59
- price: "500000000000000000", // 0.5 ETH in wei
60
- priceFormatted: "0.5",
61
- currency: {
62
- chainId: 8333,
63
- address: "0x0000000000000000000000000000000000000000", // ETH
64
- name: "Ether",
65
- symbol: "ETH",
66
- decimals: 18
67
- },
68
- name: "Cool NFT",
69
- description: "A really cool NFT",
70
- imageUrl: "https://example.com/nft.png"
71
- };
72
-
73
- return (
74
- <AnySpendNFTButton
75
- nftContract={nftContract}
76
- recipientAddress="0x..." // User's wallet address
77
- onSuccess={txHash => {
78
- console.log("NFT minted successfully!", txHash);
79
- }}
80
- />
81
- );
82
- }
83
- ```
84
-
85
- ## 📚 API Reference
86
-
87
- ### Components
88
-
89
- #### `<AnySpend>`
90
-
91
- The main swap interface component for token-to-token exchanges.
92
-
93
- ```tsx
94
- <AnySpend
95
- isMainnet={true}
96
- mode="modal" // or "page"
97
- defaultActiveTab="crypto" // or "fiat"
98
- destinationTokenAddress="0x..." // For buy mode
99
- destinationTokenChainId={8333}
100
- recipientAddress="0x..."
101
- hideTransactionHistoryButton={false}
102
- onSuccess={txHash => console.log("Swap completed", txHash)}
103
- />
104
- ```
105
-
106
- **Props:**
107
-
108
- - `isMainnet?: boolean` - Whether to use mainnet or testnet (default: `true`)
109
- - `mode?: "modal" | "page"` - Display mode (default: `"modal"`)
110
- - `defaultActiveTab?: "crypto" | "fiat"` - Initial payment method (default: `"crypto"`)
111
- - `destinationTokenAddress?: string` - For buy mode, specify the target token
112
- - `destinationTokenChainId?: number` - Chain ID of the destination token
113
- - `recipientAddress?: string` - Where to send the swapped tokens
114
- - `hideTransactionHistoryButton?: boolean` - Hide the transaction history button
115
- - `loadOrder?: string` - Load a specific order by ID
116
- - `onSuccess?: (txHash?: string) => void` - Success callback
117
-
118
- #### `<AnySpendNFTButton>`
119
-
120
- A simple button component for NFT minting.
121
-
122
- ```tsx
123
- <AnySpendNFTButton
124
- nftContract={{
125
- chainId: 8333,
126
- contractAddress: "0x...",
127
- price: "1000000000000000000", // 1 ETH in wei
128
- priceFormatted: "1.0",
129
- currency: {
130
- /* token details */
131
- },
132
- name: "My NFT",
133
- description: "NFT description",
134
- imageUrl: "https://example.com/image.png"
135
- }}
136
- recipientAddress="0x..."
137
- isMainnet={true}
138
- />
139
- ```
140
-
141
- #### `<AnySpendCustom>`
142
-
143
- For custom smart contract interactions.
144
-
145
- ```tsx
146
- <AnySpendCustom
147
- orderType={OrderType.Custom}
148
- dstChainId={8333}
149
- dstToken={
150
- {
151
- /* token details */
152
- }
153
- }
154
- dstAmount="1000000000000000000" // Amount in wei
155
- contractAddress="0x..." // Target contract
156
- encodedData="0x..." // Encoded function call
157
- spenderAddress="0x..." // Optional spender
158
- metadata={
159
- {
160
- /* custom metadata */
161
- }
162
- }
163
- header={({ anyspendPrice, isLoadingAnyspendPrice }) => <div>Custom header content</div>}
164
- onSuccess={txHash => console.log("Custom order completed", txHash)}
165
- />
166
- ```
167
-
168
- > **Note**: For specific use cases like staking, spin wheels, or other gaming mechanics, there are specialized components available (`AnySpendStakeB3`, `AnySpendBuySpin`, etc.). However, `AnySpendCustom` provides the most flexibility for any smart contract interaction.
169
-
170
- ### Hooks
171
-
172
- #### `useAnyspendQuote`
173
-
174
- Get pricing information for a potential order.
175
-
176
- ```tsx
177
- import { useAnyspendQuote, OrderType, TradeType } from "@b3dotfun/sdk/anyspend";
178
-
179
- const { anyspendQuote, isLoadingAnyspendQuote, getAnyspendQuoteError } = useAnyspendQuote(
180
- true, // isMainnet
181
- {
182
- srcChain: 1, // Ethereum
183
- dstChain: 8333, // B3
184
- srcTokenAddress: "0x...", // USDC
185
- dstTokenAddress: "0x...", // Target token
186
- type: OrderType.Swap,
187
- tradeType: TradeType.EXACT_INPUT,
188
- amount: "1000000" // 1 USDC (6 decimals)
189
- }
190
- );
191
- ```
192
-
193
- #### `useAnyspendCreateOrder`
194
-
195
- Create a new AnySpend order.
196
-
197
- ```tsx
198
- import { useAnyspendCreateOrder, OrderType } from "@b3dotfun/sdk/anyspend";
199
-
200
- const { createOrder, isCreatingOrder } = useAnyspendCreateOrder({
201
- onSuccess: data => {
202
- console.log("Order created:", data.data.id);
203
- },
204
- onError: error => {
205
- console.error("Order creation failed:", error.message);
206
- }
207
- });
208
-
209
- // Create order
210
- createOrder({
211
- isMainnet: true,
212
- recipientAddress: "0x...",
213
- orderType: OrderType.Swap,
214
- srcChain: 1,
215
- dstChain: 8333,
216
- srcToken: {
217
- /* source token details */
218
- },
219
- dstToken: {
220
- /* destination token details */
221
- },
222
- srcAmount: "1000000",
223
- expectedDstAmount: "500000000000000000",
224
- creatorAddress: "0x..."
225
- });
226
- ```
227
-
228
- #### `useAnyspendOrderAndTransactions`
229
-
230
- Track order status and associated transactions.
231
-
232
- ```tsx
233
- import { useAnyspendOrderAndTransactions } from "@b3dotfun/sdk/anyspend";
234
-
235
- const { orderAndTransactions, getOrderAndTransactionsError } = useAnyspendOrderAndTransactions(
236
- true, // isMainnet
237
- "order-id-here"
238
- );
239
-
240
- if (orderAndTransactions) {
241
- const { order, depositTxs, relayTx, executeTx, refundTxs } = orderAndTransactions.data;
242
- console.log("Order status:", order.status);
243
- console.log("Deposit transactions:", depositTxs);
244
- console.log("Execution transaction:", executeTx);
245
- }
246
- ```
247
-
248
- #### `useAnyspendOrderHistory`
249
-
250
- Get order history for a user.
251
-
252
- ```tsx
253
- import { useAnyspendOrderHistory } from "@b3dotfun/sdk/anyspend";
254
-
255
- const { orderHistory, isLoadingOrderHistory } = useAnyspendOrderHistory(
256
- true, // isMainnet
257
- "0x...", // creatorAddress
258
- 50, // limit
259
- 0 // offset
260
- );
261
- ```
262
-
263
- ### Service Functions
264
-
265
- For advanced use cases, you can use the service layer directly:
266
-
267
- ```tsx
268
- import { anyspendService } from "@b3dotfun/sdk/anyspend/services";
269
-
270
- // Get quote
271
- const quote = await anyspendService.getQuote(true, {
272
- srcChain: 1,
273
- dstChain: 8333,
274
- srcTokenAddress: "0x...",
275
- dstTokenAddress: "0x...",
276
- type: "swap",
277
- tradeType: "exactInput",
278
- amount: "1000000"
279
- });
280
-
281
- // Get token list
282
- const tokens = await anyspendService.getTokenList(true, 1, "USDC");
283
-
284
- // Create order
285
- const order = await anyspendService.createOrder({
286
- isMainnet: true,
287
- recipientAddress: "0x...",
288
- type: "swap",
289
- srcChain: 1,
290
- dstChain: 8333,
291
- srcTokenAddress: "0x...",
292
- dstTokenAddress: "0x...",
293
- srcAmount: "1000000",
294
- payload: {
295
- /* order payload */
296
- },
297
- metadata: {
298
- /* order metadata */
299
- }
300
- });
301
- ```
302
-
303
- ### Network Configuration
304
-
305
- AnySpend automatically configures API endpoints based on the `isMainnet` parameter:
306
-
307
- - **Mainnet**: `https://mainnet.anyspend.com`
308
- - **Testnet**: `http://testnet.anyspend.com`
309
-
310
- ## 💼 Common Use Cases
311
-
312
- ### 1. Cross-Chain Token Swap
313
-
314
- ```tsx
315
- import { AnySpend } from "@b3dotfun/sdk/anyspend/react";
316
-
317
- function TokenSwap() {
318
- return (
319
- <AnySpend
320
- mode="page"
321
- recipientAddress="0x..."
322
- onSuccess={txHash => {
323
- console.log("Swap completed:", txHash);
324
- // Redirect user or show success message
325
- }}
326
- />
327
- );
328
- }
329
- ```
330
-
331
- ### 2. NFT Marketplace Integration
332
-
333
- ```tsx
334
- import { AnySpendNFT } from "@b3dotfun/sdk/anyspend/react";
335
-
336
- function NFTCard({ nft }) {
337
- return (
338
- <div className="nft-card">
339
- <img src={nft.imageUrl} alt={nft.name} />
340
- <h3>{nft.name}</h3>
341
- <p>{nft.description}</p>
342
- <AnySpendNFT
343
- nftContract={nft}
344
- recipientAddress={userAddress}
345
- onSuccess={txHash => {
346
- // Update UI to show NFT as owned
347
- updateNFTOwnership(nft.id, userAddress);
348
- }}
349
- />
350
- </div>
351
- );
352
- }
353
- ```
354
-
355
- ### 3. Custom Contract Interaction - Staking Example
356
-
357
- ```tsx
358
- import { AnySpendCustom, OrderType } from "@b3dotfun/sdk/anyspend/react";
359
-
360
- function StakingInterface({ stakingContract }) {
361
- return (
362
- <AnySpendCustom
363
- orderType={OrderType.Custom}
364
- dstChainId={stakingContract.chainId}
365
- dstToken={stakingContract.stakingToken}
366
- dstAmount={stakingContract.stakeAmount}
367
- contractAddress={stakingContract.contractAddress}
368
- encodedData={stakingContract.stakeCalldata} // encoded stake() function call
369
- metadata={{
370
- action: "stake",
371
- staking: {
372
- contractAddress: stakingContract.contractAddress,
373
- amount: stakingContract.stakeAmount,
374
- duration: stakingContract.duration
375
- }
376
- }}
377
- header={({ anyspendPrice }) => (
378
- <div className="staking-header">
379
- <h2>Stake {stakingContract.stakingToken.symbol}</h2>
380
- <p>
381
- Amount: {stakingContract.stakeAmountFormatted} {stakingContract.stakingToken.symbol}
382
- </p>
383
- <p>Duration: {stakingContract.duration} days</p>
384
- </div>
385
- )}
386
- onSuccess={txHash => {
387
- console.log("Staking completed:", txHash);
388
- // Update UI to show staked amount
389
- }}
390
- />
391
- );
392
- }
393
- ```
394
-
395
- ### 4. Fiat to Crypto Onramp
396
-
397
- ```tsx
398
- import { AnySpend } from "@b3dotfun/sdk/anyspend/react";
399
-
400
- function FiatOnramp() {
401
- return (
402
- <AnySpend
403
- defaultActiveTab="fiat"
404
- destinationTokenAddress="0x..." // Target token to buy
405
- destinationTokenChainId={8333}
406
- recipientAddress="0x..."
407
- onSuccess={txHash => {
408
- console.log("Fiat purchase completed:", txHash);
409
- }}
410
- />
411
- );
412
- }
413
- ```
414
-
415
- ## ⚠️ Error Handling
416
-
417
- ### Order Status Types
418
-
419
- AnySpend orders go through various states:
420
-
421
- ```typescript
422
- enum OrderStatus {
423
- // Preparation
424
- ScanningDepositTransaction = "scanning_deposit_transaction",
425
- WaitingStripePayment = "waiting_stripe_payment",
426
- ObtainToken = "obtain_token",
427
-
428
- // Execution
429
- SendingTokenFromVault = "sending_token_from_vault",
430
- Relay = "relay",
431
- Executed = "executed",
432
-
433
- // Failure/Refund
434
- ObtainFailed = "obtain_failed",
435
- Expired = "expired",
436
- Refunding = "refunding",
437
- Refunded = "refunded",
438
- Failure = "failure"
439
- }
440
- ```
441
-
442
- ### Common Error Codes
443
-
444
- | Error Code | Description | Recovery Strategy |
445
- | ---------------------- | --------------------------------- | ------------------------------------ |
446
- | `SLIPPAGE` | Price movement exceeded tolerance | Retry with higher slippage tolerance |
447
- | `INSUFFICIENT_BALANCE` | User doesn't have enough tokens | Request user to add funds |
448
- | `NETWORK_ERROR` | RPC or network issues | Retry after a delay |
449
- | `QUOTE_EXPIRED` | Price quote is no longer valid | Get a fresh quote |
450
-
451
- ### Error Handling Best Practices
452
-
453
- ```tsx
454
- import { useAnyspendCreateOrder } from "@b3dotfun/sdk/anyspend";
455
-
456
- const { createOrder, isCreatingOrder } = useAnyspendCreateOrder({
457
- onError: error => {
458
- switch (error.message) {
459
- case "SLIPPAGE":
460
- toast.error("Price moved unfavorably. Please try again.");
461
- break;
462
- case "INSUFFICIENT_BALANCE":
463
- toast.error("Insufficient balance. Please add funds to your wallet.");
464
- break;
465
- default:
466
- toast.error("Transaction failed. Please try again or contact support.");
467
- }
468
-
469
- // Log for debugging
470
- console.error("Order creation failed:", error);
471
-
472
- // Optional: Send to error tracking service
473
- // errorTracking.captureException(error);
474
- }
475
- });
476
- ```
477
-
478
- ### Order Monitoring
479
-
480
- ```tsx
481
- import { useAnyspendOrderAndTransactions, OrderStatus } from "@b3dotfun/sdk/anyspend";
482
-
483
- function OrderTracker({ orderId }) {
484
- const { orderAndTransactions } = useAnyspendOrderAndTransactions(true, orderId);
485
-
486
- if (!orderAndTransactions) return <div>Loading...</div>;
487
-
488
- const { order, depositTxs, executeTx, refundTxs } = orderAndTransactions.data;
489
-
490
- const getStatusMessage = (status: OrderStatus) => {
491
- switch (status) {
492
- case OrderStatus.ScanningDepositTransaction:
493
- return "Waiting for payment confirmation...";
494
- case OrderStatus.Relay:
495
- return "Processing your transaction...";
496
- case OrderStatus.Executed:
497
- return "Transaction completed successfully!";
498
- case OrderStatus.Failure:
499
- return "Transaction failed. You will be refunded automatically.";
500
- case OrderStatus.Refunded:
501
- return "Refund processed successfully.";
502
- default:
503
- return "Processing...";
504
- }
505
- };
506
-
507
- return (
508
- <div className="order-status">
509
- <h3>Order Status: {order.status}</h3>
510
- <p>{getStatusMessage(order.status)}</p>
511
-
512
- {order.errorDetails && (
513
- <div className="error-details">
514
- <strong>Error:</strong> {order.errorDetails}
515
- </div>
516
- )}
517
-
518
- {executeTx && (
519
- <a href={`https://explorer.b3.fun/tx/${executeTx.txHash}`} target="_blank" rel="noopener noreferrer">
520
- View Transaction
521
- </a>
522
- )}
523
- </div>
524
- );
525
- }
526
- ```
527
-
528
- ## 🌐 Platform Support
529
-
530
- | Feature | React Web | React Native |
531
- | ----------------- | --------- | ------------ |
532
- | Core AnySpend | ✅ | ✅ |
533
- | React Components | ✅ | ✅ |
534
- | Fiat Onramp | ✅ | ❌ |
535
- | NFT Components | ✅ | ✅ |
536
- | Service Functions | ✅ | ✅ |
537
-
538
- ## 🐛 Troubleshooting
539
-
540
- ### Common Issues
541
-
542
- **Q: "Get rate error" appears when trying to swap**
543
-
544
- ```
545
- A: This usually means:
546
- 1. Invalid token addresses
547
- 2. Unsupported token pair
548
- 3. Amount too small/large
549
- 4. Network connectivity issues
550
-
551
- Check that both tokens are supported and try with a different amount.
552
- ```
553
-
554
- **Q: Order stuck in "scanning_deposit_transaction" status**
555
-
556
- ```
557
- A: This means AnySpend is waiting for your deposit transaction to be confirmed.
558
- Check that:
559
- 1. You sent the correct amount
560
- 2. Transaction was confirmed on-chain
561
- 3. You sent to the correct address
562
-
563
- Orders will auto-refund after 30 minutes if no deposit is detected.
564
- ```
565
-
566
- **Q: React Native build issues**
567
-
568
- ```
569
- A: Make sure you're importing from the correct entry point:
570
-
571
- // ✅ Correct
572
- import { anyspendService } from "@b3dotfun/sdk/anyspend";
573
-
574
- // ❌ Incorrect for React Native
575
- import { AnySpend } from "@b3dotfun/sdk/anyspend/react";
576
- ```
577
-
578
- ### Debug Mode
579
-
580
- Enable debug logging to troubleshoot issues:
581
-
582
- ```typescript
583
- // Add to your app initialization
584
- localStorage.setItem("debug", "anyspend:*");
585
-
586
- // Or in React Native
587
- import { anyspendService } from "@b3dotfun/sdk/anyspend";
588
-
589
- // Service calls will now log detailed information
590
- const quote = await anyspendService.getQuote(true, quoteRequest);
591
- ```
592
-
593
- ### Support Channels
594
-
595
- - **Documentation**: [https://docs.b3.fun](https://docs.b3.fun)
596
- - **GitHub Issues**: [https://github.com/b3-fun/b3/issues](https://github.com/b3-fun/b3/issues)
597
- - **Discord**: [https://discord.gg/b3dotfun](https://discord.gg/b3dotfun)
598
-
599
- ## 🤝 Contributing
600
-
601
- We welcome contributions! Here's how to get started:
602
-
603
- 1. **Fork the repository**
604
- 2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
605
- 3. **Install dependencies**: `pnpm install`
606
- 4. **Run tests**: `pnpm test`
607
- 5. **Build the SDK**: `pnpm sdk:build`
608
- 6. **Test your changes** in the example apps
609
- 7. **Submit a pull request**
610
-
611
- ### Development Setup
612
-
613
- ```bash
614
- # Clone the repo
615
- git clone https://github.com/b3-fun/b3.git
616
- cd b3
617
-
618
- # Install dependencies
619
- pnpm install
620
-
621
- # Start development
622
- pnpm dev
623
-
624
- # Build the SDK
625
- pnpm sdk:build
626
- ```