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