@b3dotfun/sdk 0.0.9-alpha.2 → 0.0.9-alpha.4

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.
@@ -0,0 +1,292 @@
1
+ # Components API Reference
2
+
3
+ AnySpend provides a collection of React components designed to integrate seamlessly into your application for various crypto payment and interaction scenarios.
4
+
5
+ ## Core Components
6
+
7
+ ### `<AnySpend>`
8
+
9
+ The primary interface component for token-to-token exchanges and fiat onramps.
10
+
11
+ ```tsx
12
+ import { AnySpend } from "@b3dotfun/sdk/anyspend/react";
13
+
14
+ <AnySpend
15
+ isMainnet={true}
16
+ mode="modal"
17
+ defaultActiveTab="crypto"
18
+ destinationTokenAddress="0x..."
19
+ destinationTokenChainId={8333}
20
+ recipientAddress="0x..."
21
+ hideTransactionHistoryButton={false}
22
+ onSuccess={(txHash) => console.log("Swap completed", txHash)}
23
+ />
24
+ ```
25
+
26
+ #### Props
27
+
28
+ | Prop | Type | Default | Description |
29
+ |------|------|---------|-------------|
30
+ | `isMainnet` | `boolean` | `true` | Use mainnet or testnet environment |
31
+ | `mode` | `"modal" \| "page"` | `"modal"` | Display as modal overlay or full page |
32
+ | `defaultActiveTab` | `"crypto" \| "fiat"` | `"crypto"` | Initial payment method tab |
33
+ | `destinationTokenAddress` | `string` | - | Target token address for buy mode |
34
+ | `destinationTokenChainId` | `number` | - | Chain ID of destination token |
35
+ | `recipientAddress` | `string` | - | Recipient wallet address |
36
+ | `hideTransactionHistoryButton` | `boolean` | `false` | Hide transaction history access |
37
+ | `loadOrder` | `string` | - | Load specific order by ID |
38
+ | `onSuccess` | `(txHash?: string) => void` | - | Success callback with transaction hash |
39
+
40
+ #### Usage Examples
41
+
42
+ **Basic Token Swap:**
43
+ ```tsx
44
+ <AnySpend
45
+ mode="page"
46
+ recipientAddress={userWalletAddress}
47
+ onSuccess={(txHash) => {
48
+ toast.success(`Swap completed! TX: ${txHash}`);
49
+ }}
50
+ />
51
+ ```
52
+
53
+ **Fiat-to-Crypto Onramp:**
54
+ ```tsx
55
+ <AnySpend
56
+ defaultActiveTab="fiat"
57
+ destinationTokenAddress="0xA0b86a33E6Fb6Dd9a9B3d8B5FEb2b3C8e7D9Ff1E"
58
+ destinationTokenChainId={8333}
59
+ recipientAddress={userWalletAddress}
60
+ />
61
+ ```
62
+
63
+ ---
64
+
65
+ ### `<AnySpendNFTButton>`
66
+
67
+ A streamlined button component for NFT purchases with built-in payment handling.
68
+
69
+ ```tsx
70
+ import { AnySpendNFTButton } from "@b3dotfun/sdk/anyspend/react";
71
+
72
+ <AnySpendNFTButton
73
+ nftContract={nftContractDetails}
74
+ recipientAddress="0x..."
75
+ isMainnet={true}
76
+ onSuccess={(txHash) => console.log("NFT minted:", txHash)}
77
+ />
78
+ ```
79
+
80
+ #### Props
81
+
82
+ | Prop | Type | Required | Description |
83
+ |------|------|----------|-------------|
84
+ | `nftContract` | `NFTContract` | ✅ | NFT contract configuration |
85
+ | `recipientAddress` | `string` | ✅ | Wallet to receive the NFT |
86
+ | `isMainnet` | `boolean` | - | Environment selection |
87
+ | `onSuccess` | `(txHash?: string) => void` | - | Success callback |
88
+
89
+ #### NFTContract Interface
90
+
91
+ ```typescript
92
+ interface NFTContract {
93
+ chainId: number; // Blockchain network ID
94
+ contractAddress: string; // NFT contract address
95
+ price: string; // Price in wei
96
+ priceFormatted: string; // Human-readable price
97
+ currency: {
98
+ chainId: number;
99
+ address: string; // Token contract (0x0 for native ETH)
100
+ name: string;
101
+ symbol: string;
102
+ decimals: number;
103
+ };
104
+ name: string; // NFT collection name
105
+ description: string; // NFT description
106
+ imageUrl: string; // Preview image URL
107
+ }
108
+ ```
109
+
110
+ #### Usage Example
111
+
112
+ ```tsx
113
+ const coolNFT = {
114
+ chainId: 8333,
115
+ contractAddress: "0x9c275ff1634519E9B5449ec79cd939B5F900564d",
116
+ price: "500000000000000000", // 0.5 ETH
117
+ priceFormatted: "0.5",
118
+ currency: {
119
+ chainId: 8333,
120
+ address: "0x0000000000000000000000000000000000000000",
121
+ name: "Ether",
122
+ symbol: "ETH",
123
+ decimals: 18,
124
+ },
125
+ name: "Cool Art Collection",
126
+ description: "Unique digital artwork",
127
+ imageUrl: "https://example.com/nft-preview.png",
128
+ };
129
+
130
+ <AnySpendNFTButton
131
+ nftContract={coolNFT}
132
+ recipientAddress={userAddress}
133
+ onSuccess={(txHash) => {
134
+ // Update UI to show NFT ownership
135
+ refreshUserNFTs();
136
+ }}
137
+ />
138
+ ```
139
+
140
+ ---
141
+
142
+ ### `<AnySpendCustom>`
143
+
144
+ The most flexible component for custom smart contract interactions, including gaming, staking, and DeFi operations.
145
+
146
+ ```tsx
147
+ import { AnySpendCustom } from "@b3dotfun/sdk/anyspend/react";
148
+
149
+ <AnySpendCustom
150
+ orderType="custom"
151
+ dstChainId={8333}
152
+ dstToken={tokenDetails}
153
+ dstAmount="1000000000000000000"
154
+ contractAddress="0x..."
155
+ encodedData="0x..."
156
+ spenderAddress="0x..."
157
+ metadata={customMetadata}
158
+ header={CustomHeaderComponent}
159
+ onSuccess={(txHash) => console.log("Custom action completed", txHash)}
160
+ />
161
+ ```
162
+
163
+ #### Props
164
+
165
+ | Prop | Type | Required | Description |
166
+ |------|------|----------|-------------|
167
+ | `orderType` | `"custom"` | ✅ | Order type identifier |
168
+ | `dstChainId` | `number` | ✅ | Target blockchain network |
169
+ | `dstToken` | `Token` | ✅ | Token being used for payment |
170
+ | `dstAmount` | `string` | ✅ | Amount in wei/smallest unit |
171
+ | `contractAddress` | `string` | ✅ | Target smart contract |
172
+ | `encodedData` | `string` | ✅ | Encoded function call data |
173
+ | `spenderAddress` | `string` | - | Optional token spender |
174
+ | `metadata` | `object` | - | Custom metadata for tracking |
175
+ | `header` | `React.ComponentType` | - | Custom header component |
176
+ | `onSuccess` | `(txHash?: string) => void` | - | Success callback |
177
+
178
+ #### Usage Example - Staking
179
+
180
+ ```tsx
181
+ // Encode staking function call
182
+ const stakeAmount = "1000000000000000000"; // 1 token
183
+ const stakingCalldata = encodeFunctionData({
184
+ abi: stakingABI,
185
+ functionName: "stake",
186
+ args: [stakeAmount, 30] // 30 days
187
+ });
188
+
189
+ <AnySpendCustom
190
+ orderType="custom"
191
+ dstChainId={8333}
192
+ dstToken={stakingToken}
193
+ dstAmount={stakeAmount}
194
+ contractAddress="0xStakingContract..."
195
+ encodedData={stakingCalldata}
196
+ metadata={{
197
+ action: "stake",
198
+ duration: 30,
199
+ expectedRewards: "5.2%"
200
+ }}
201
+ header={({ anyspendPrice, isLoadingAnyspendPrice }) => (
202
+ <div className="staking-header">
203
+ <h2>Stake Tokens</h2>
204
+ <p>Duration: 30 days</p>
205
+ <p>Expected APY: 5.2%</p>
206
+ {!isLoadingAnyspendPrice && (
207
+ <p>Total Cost: ${anyspendPrice?.usdPrice}</p>
208
+ )}
209
+ </div>
210
+ )}
211
+ />
212
+ ```
213
+
214
+ ## Specialized Components
215
+
216
+ ### `<AnySpendNFT>`
217
+
218
+ Enhanced NFT component with additional marketplace features.
219
+
220
+ ```tsx
221
+ <AnySpendNFT
222
+ nftContract={nftDetails}
223
+ recipientAddress="0x..."
224
+ showMetadata={true}
225
+ showPriceHistory={true}
226
+ />
227
+ ```
228
+
229
+ ### `<AnySpendStakeB3>`
230
+
231
+ Pre-configured component for B3 token staking.
232
+
233
+ ```tsx
234
+ <AnySpendStakeB3
235
+ stakeAmount="1000000000000000000"
236
+ stakingDuration={30}
237
+ recipientAddress="0x..."
238
+ />
239
+ ```
240
+
241
+ ### `<AnySpendBuySpin>`
242
+
243
+ Gaming-specific component for purchasing spin wheels or lottery tickets.
244
+
245
+ ```tsx
246
+ <AnySpendBuySpin
247
+ gameContract="0x..."
248
+ spinPrice="100000000000000000"
249
+ recipientAddress="0x..."
250
+ />
251
+ ```
252
+
253
+ ### `<AnySpendTournament>`
254
+
255
+ Tournament entry payment component.
256
+
257
+ ```tsx
258
+ <AnySpendTournament
259
+ tournamentId="tournament-123"
260
+ entryFee="500000000000000000"
261
+ recipientAddress="0x..."
262
+ />
263
+ ```
264
+
265
+ ## Component Styling
266
+
267
+ All components come with default styling that can be customized:
268
+
269
+ ```css
270
+ /* Override default styles */
271
+ .anyspend-modal {
272
+ --anyspend-primary: #6366f1;
273
+ --anyspend-secondary: #f3f4f6;
274
+ --anyspend-border-radius: 12px;
275
+ }
276
+ ```
277
+
278
+ ## Platform Support
279
+
280
+ | Component | React Web | React Native |
281
+ |-----------|-----------|--------------|
282
+ | `AnySpend` | ✅ | ✅ |
283
+ | `AnySpendNFTButton` | ✅ | ✅ |
284
+ | `AnySpendCustom` | ✅ | ✅ |
285
+ | `AnySpendNFT` | ✅ | ✅ |
286
+ | Fiat onramp features | ✅ | ❌ |
287
+
288
+ ## Next Steps
289
+
290
+ - [Learn about Hooks →](./hooks.md)
291
+ - [See Examples →](./examples.md)
292
+ - [Error Handling →](./error-handling.md)