@b3dotfun/sdk 0.0.1-alpha.2 → 0.0.1-alpha.20
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 +328 -230
- package/dist/cjs/anyspend/index.native.d.ts +13 -0
- package/dist/cjs/anyspend/index.native.js +35 -0
- package/dist/cjs/anyspend/react/components/AnySpend.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpend.js +4 -4
- package/dist/cjs/anyspend/react/components/AnySpendBuySpin.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpendBuySpin.js +123 -50
- package/dist/cjs/anyspend/react/components/common/OrderHistoryItem.js +5 -1
- package/dist/cjs/anyspend/react/components/common/TokenBalance.js +1 -1
- package/dist/cjs/anyspend/utils/chain.js +3 -0
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +2 -2
- package/dist/cjs/global-account/react/components/{B3Provider.d.ts → B3Provider/B3Provider.d.ts} +3 -29
- package/dist/cjs/global-account/react/components/{B3Provider.js → B3Provider/B3Provider.js} +6 -34
- package/dist/cjs/global-account/react/components/{B3Provider.native.d.ts → B3Provider/B3Provider.native.d.ts} +2 -25
- package/dist/cjs/global-account/react/components/{B3Provider.native.js → B3Provider/B3Provider.native.js} +5 -28
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +25 -0
- package/dist/cjs/global-account/react/components/B3Provider/types.js +20 -0
- package/dist/cjs/global-account/react/components/B3Provider/useB3.d.ts +5 -0
- package/dist/cjs/global-account/react/components/B3Provider/useB3.js +17 -0
- package/dist/cjs/global-account/react/components/StyleRoot.js +2 -2
- package/dist/cjs/global-account/react/components/index.d.ts +8 -6
- package/dist/cjs/global-account/react/components/index.js +18 -16
- package/dist/cjs/global-account/react/hooks/index.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/index.js +2 -1
- package/dist/cjs/global-account/react/hooks/useBestTransactionPath.js +3 -3
- package/dist/cjs/global-account/react/hooks/useTokenBalance.js +1 -1
- package/dist/cjs/global-account/react/index.native.d.ts +7 -0
- package/dist/cjs/global-account/react/index.native.js +21 -0
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +2 -0
- package/dist/cjs/global-account/types/chain-networks.d.ts +34 -34
- package/dist/cjs/global-account/types/feature-flags.d.ts +5 -5
- package/dist/cjs/shared/constants/chains/b3Chain.d.ts +1 -1
- package/dist/cjs/shared/constants/chains/supported.d.ts +8 -7
- package/dist/cjs/shared/constants/chains/supported.js +8 -1
- package/dist/cjs/shared/utils/chains.js +4 -0
- package/dist/cjs/shared/utils/number.js +1 -1
- package/dist/esm/anyspend/index.native.d.ts +13 -0
- package/dist/esm/anyspend/index.native.js +19 -0
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +4 -4
- package/dist/esm/anyspend/react/components/AnySpendBuySpin.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +123 -50
- package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +5 -1
- package/dist/esm/anyspend/react/components/common/TokenBalance.js +1 -1
- package/dist/esm/anyspend/utils/chain.js +3 -0
- package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -1
- package/dist/esm/global-account/react/components/{B3Provider.d.ts → B3Provider/B3Provider.d.ts} +3 -29
- package/dist/esm/global-account/react/components/{B3Provider.js → B3Provider/B3Provider.js} +5 -32
- package/dist/esm/global-account/react/components/{B3Provider.native.d.ts → B3Provider/B3Provider.native.d.ts} +2 -25
- package/dist/esm/global-account/react/components/{B3Provider.native.js → B3Provider/B3Provider.native.js} +5 -26
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +25 -0
- package/dist/esm/global-account/react/components/B3Provider/types.js +17 -0
- package/dist/esm/global-account/react/components/B3Provider/useB3.d.ts +5 -0
- package/dist/esm/global-account/react/components/B3Provider/useB3.js +14 -0
- package/dist/esm/global-account/react/components/StyleRoot.js +1 -1
- package/dist/esm/global-account/react/components/index.d.ts +8 -6
- package/dist/esm/global-account/react/components/index.js +7 -5
- package/dist/esm/global-account/react/hooks/index.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/index.js +1 -1
- package/dist/esm/global-account/react/hooks/useBestTransactionPath.js +3 -3
- package/dist/esm/global-account/react/hooks/useTokenBalance.js +1 -1
- package/dist/esm/global-account/react/index.native.d.ts +7 -0
- package/dist/esm/global-account/react/index.native.js +11 -0
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +2 -0
- package/dist/esm/global-account/types/chain-networks.d.ts +34 -34
- package/dist/esm/global-account/types/feature-flags.d.ts +5 -5
- package/dist/esm/shared/constants/chains/b3Chain.d.ts +1 -1
- package/dist/esm/shared/constants/chains/supported.d.ts +8 -7
- package/dist/esm/shared/constants/chains/supported.js +7 -0
- package/dist/esm/shared/utils/chains.js +4 -0
- package/dist/esm/shared/utils/number.js +1 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/index.native.d.ts +13 -0
- package/dist/types/anyspend/react/components/AnySpend.d.ts +2 -1
- package/dist/types/anyspend/react/components/AnySpendBuySpin.d.ts +2 -1
- package/dist/types/global-account/react/components/{B3Provider.d.ts → B3Provider/B3Provider.d.ts} +2 -28
- package/dist/types/global-account/react/components/{B3Provider.native.d.ts → B3Provider/B3Provider.native.d.ts} +1 -24
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +25 -0
- package/dist/types/global-account/react/components/B3Provider/useB3.d.ts +5 -0
- package/dist/types/global-account/react/components/index.d.ts +8 -6
- package/dist/types/global-account/react/hooks/index.d.ts +1 -1
- package/dist/types/global-account/react/index.native.d.ts +7 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +2 -0
- package/dist/types/global-account/types/chain-networks.d.ts +34 -34
- package/dist/types/global-account/types/feature-flags.d.ts +5 -5
- package/dist/types/shared/constants/chains/b3Chain.d.ts +1 -1
- package/dist/types/shared/constants/chains/supported.d.ts +8 -7
- package/package.json +26 -24
- package/src/anyspend/index.native.ts +24 -0
- package/src/anyspend/react/components/AnySpend.tsx +6 -5
- package/src/anyspend/react/components/AnySpendBuySpin.tsx +232 -179
- package/src/anyspend/react/components/common/OrderHistoryItem.tsx +5 -1
- package/src/anyspend/react/components/common/TokenBalance.tsx +1 -1
- package/src/anyspend/utils/chain.ts +3 -0
- package/src/global-account/react/components/B3DynamicModal.tsx +1 -1
- package/src/global-account/react/components/{B3Provider.native.tsx → B3Provider/B3Provider.native.tsx} +4 -45
- package/src/global-account/react/components/{B3Provider.tsx → B3Provider/B3Provider.tsx} +4 -53
- package/src/global-account/react/components/B3Provider/types.ts +40 -0
- package/src/global-account/react/components/B3Provider/useB3.ts +17 -0
- package/src/global-account/react/components/StyleRoot.tsx +1 -1
- package/src/global-account/react/components/index.ts +8 -6
- package/src/global-account/react/hooks/index.ts +1 -1
- package/src/global-account/react/hooks/useBestTransactionPath.tsx +3 -3
- package/src/global-account/react/hooks/useTokenBalance.tsx +1 -1
- package/src/global-account/react/index.native.ts +14 -0
- package/src/global-account/react/stores/useModalStore.ts +2 -0
- package/src/shared/constants/chains/supported.ts +12 -4
- package/src/shared/utils/chains.ts +4 -1
- package/src/shared/utils/number.ts +1 -1
- package/dist/cjs/styles/index.d.ts +0 -20
- package/dist/cjs/styles/index.js +0 -22
- package/dist/esm/styles/index.d.ts +0 -20
- package/dist/esm/styles/index.js +0 -20
- package/dist/types/styles/index.d.ts +0 -20
- package/src/styles/index.ts +0 -24
package/README.md
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
# @b3dotfun/sdk
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A comprehensive TypeScript SDK for AnySpend cross-chain operations and B3 Global Accounts authentication. Provides both React components for easy integration and headless TypeScript services for custom implementations.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
The SDK is organized into focused modules:
|
|
8
|
+
|
|
9
|
+
- **`anyspend/`** - Cross-chain execution engine functionality
|
|
10
|
+
- **`global-account/`** - B3 Global Accounts authentication and user management
|
|
11
|
+
- **`shared/`** - Common utilities, types, and components
|
|
12
|
+
- **`others/`** - Additional features and utilities
|
|
13
|
+
|
|
14
|
+
Each module contains:
|
|
15
|
+
- `react/` - React components and hooks
|
|
16
|
+
- `services/` - Headless TypeScript services
|
|
17
|
+
- `types/` - TypeScript definitions
|
|
18
|
+
- `utils/` - Utility functions
|
|
19
|
+
- `constants/` - Constants and configuration
|
|
20
|
+
|
|
21
|
+
## Platform Support
|
|
6
22
|
|
|
7
23
|
| Feature | React Web | React Native |
|
|
8
24
|
| ---------------------- | --------- | ------------ |
|
|
9
25
|
| AnySpend | ✅ | ❌ |
|
|
10
|
-
| Global Accounts
|
|
26
|
+
| Global Accounts | ✅ | ✅ |
|
|
27
|
+
| Headless Services | ✅ | ✅ |
|
|
11
28
|
|
|
12
29
|
## Installation
|
|
13
30
|
|
|
@@ -19,45 +36,186 @@ yarn add @b3dotfun/sdk
|
|
|
19
36
|
pnpm add @b3dotfun/sdk
|
|
20
37
|
```
|
|
21
38
|
|
|
22
|
-
##
|
|
39
|
+
## CSS Styles
|
|
23
40
|
|
|
24
|
-
|
|
25
|
-
|
|
41
|
+
```tsx
|
|
42
|
+
import "@b3dotfun/sdk/index.css"; // Import default styles
|
|
43
|
+
```
|
|
26
44
|
|
|
27
45
|
# AnySpend
|
|
28
46
|
|
|
29
|
-
|
|
47
|
+
AnySpend enables cross-chain swaps, NFT minting, and other blockchain operations with a unified interface.
|
|
30
48
|
|
|
31
|
-
|
|
49
|
+
## React Components
|
|
32
50
|
|
|
33
|
-
|
|
51
|
+
### Basic Cross-Chain Swap
|
|
34
52
|
|
|
35
|
-
|
|
53
|
+
```tsx
|
|
54
|
+
import { AnySpend } from "@b3dotfun/sdk/anyspend/react";
|
|
36
55
|
|
|
37
|
-
|
|
56
|
+
function CrossChainSwapPage() {
|
|
57
|
+
return (
|
|
58
|
+
<AnySpend
|
|
59
|
+
isMainnet={true}
|
|
60
|
+
mode="page"
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### NFT Minting
|
|
38
67
|
|
|
39
68
|
```tsx
|
|
40
|
-
import {
|
|
41
|
-
|
|
69
|
+
import { AnySpendNFTButton } from "@b3dotfun/sdk/anyspend/react";
|
|
70
|
+
|
|
71
|
+
function NFTMinting() {
|
|
72
|
+
const nftContract = {
|
|
73
|
+
address: "0x9c275ff1634519E9B5449ec79cd939B5F900564d",
|
|
74
|
+
chainId: 8333,
|
|
75
|
+
name: "Example NFT Collection",
|
|
76
|
+
imageUrl: "https://example.com/nft-image.jpg",
|
|
77
|
+
description: "A beautiful NFT from our collection",
|
|
78
|
+
price: "1000000000000000000", // 1 ETH in wei
|
|
79
|
+
currency: {
|
|
80
|
+
symbol: "ETH",
|
|
81
|
+
decimals: 18
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<AnySpendNFTButton
|
|
87
|
+
nftContract={nftContract}
|
|
88
|
+
recipientAddress="0x..."
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Custom Integration with Provider
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
import { AnyspendProvider } from "@b3dotfun/sdk/anyspend/react";
|
|
42
98
|
|
|
43
99
|
function App() {
|
|
44
|
-
return
|
|
100
|
+
return (
|
|
101
|
+
<AnyspendProvider isMainnet={true}>
|
|
102
|
+
<YourAnySpendComponents />
|
|
103
|
+
</AnyspendProvider>
|
|
104
|
+
);
|
|
45
105
|
}
|
|
46
106
|
```
|
|
47
107
|
|
|
48
|
-
|
|
108
|
+
## Headless TypeScript Services
|
|
109
|
+
|
|
110
|
+
### Token Operations
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { anyspendService } from "@b3dotfun/sdk/anyspend/services/anyspend";
|
|
114
|
+
|
|
115
|
+
// Get available tokens for a chain
|
|
116
|
+
const tokens = await anyspendService.getTokenList(
|
|
117
|
+
true, // isMainnet
|
|
118
|
+
1, // chainId (Ethereum)
|
|
119
|
+
"usdc" // search query
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
// Get specific token details
|
|
123
|
+
const token = await anyspendService.getToken(
|
|
124
|
+
true, // isMainnet
|
|
125
|
+
1, // chainId
|
|
126
|
+
"0xA0b86a33E6c51c7C36c654d6C9e7b8F5d4a8b5c5" // token address
|
|
127
|
+
);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Quote and Order Management
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { anyspendService } from "@b3dotfun/sdk/anyspend/services/anyspend";
|
|
134
|
+
import type { GetQuoteRequest } from "@b3dotfun/sdk/anyspend/types";
|
|
135
|
+
|
|
136
|
+
// Get quote for cross-chain swap
|
|
137
|
+
const quoteRequest: GetQuoteRequest = {
|
|
138
|
+
srcChain: 1,
|
|
139
|
+
dstChain: 8333,
|
|
140
|
+
srcTokenAddress: "0xA0b86a33E6c51c7C36c654d6C9e7b8F5d4a8b5c5",
|
|
141
|
+
dstTokenAddress: "0x...",
|
|
142
|
+
srcAmount: "1000000", // 1 USDC
|
|
143
|
+
recipientAddress: "0x...",
|
|
144
|
+
type: "swap"
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const quote = await anyspendService.getQuote(true, quoteRequest);
|
|
148
|
+
|
|
149
|
+
// Create order
|
|
150
|
+
const order = await anyspendService.createOrder({
|
|
151
|
+
isMainnet: true,
|
|
152
|
+
recipientAddress: "0x...",
|
|
153
|
+
type: "swap",
|
|
154
|
+
srcChain: 1,
|
|
155
|
+
dstChain: 8333,
|
|
156
|
+
srcTokenAddress: "0x...",
|
|
157
|
+
dstTokenAddress: "0x...",
|
|
158
|
+
srcAmount: "1000000",
|
|
159
|
+
payload: {},
|
|
160
|
+
metadata: {}
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Order Tracking
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
import { anyspendService } from "@b3dotfun/sdk/anyspend/services/anyspend";
|
|
168
|
+
|
|
169
|
+
// Get order details and transactions
|
|
170
|
+
const orderDetails = await anyspendService.getOrderAndTransactions(
|
|
171
|
+
true, // isMainnet
|
|
172
|
+
"order-id"
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
// Get order history for an address
|
|
176
|
+
const history = await anyspendService.getOrderHistory(
|
|
177
|
+
true, // isMainnet
|
|
178
|
+
"0x...", // creator address
|
|
179
|
+
50, // limit
|
|
180
|
+
0 // offset
|
|
181
|
+
);
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Utility Functions
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { isNativeToken, getNativeToken } from "@b3dotfun/sdk/anyspend/utils";
|
|
188
|
+
import { formatAmount } from "@b3dotfun/sdk/anyspend/utils";
|
|
189
|
+
|
|
190
|
+
// Check if token is native
|
|
191
|
+
const isNative = isNativeToken("0x0000000000000000000000000000000000000000");
|
|
192
|
+
|
|
193
|
+
// Get native token info
|
|
194
|
+
const nativeToken = getNativeToken(1); // Ethereum
|
|
195
|
+
|
|
196
|
+
// Format token amounts
|
|
197
|
+
const formatted = formatAmount("1000000000000000000", 18); // "1.0"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
# Global Accounts
|
|
201
|
+
|
|
202
|
+
B3 Global Accounts provide seamless authentication and user management across the B3 ecosystem.
|
|
203
|
+
|
|
204
|
+
## React Components
|
|
205
|
+
|
|
206
|
+
### Basic Authentication
|
|
49
207
|
|
|
50
208
|
```tsx
|
|
51
|
-
import {
|
|
209
|
+
import { B3Provider, SignInWithB3 } from "@b3dotfun/sdk/global-account/react";
|
|
52
210
|
|
|
53
211
|
function App() {
|
|
54
212
|
return (
|
|
55
213
|
<B3Provider environment="production">
|
|
56
214
|
<SignInWithB3
|
|
57
|
-
|
|
58
|
-
partnerId="
|
|
59
|
-
onLoginSuccess={globalAccount => {
|
|
60
|
-
console.log("
|
|
215
|
+
provider={{ strategy: "google" }}
|
|
216
|
+
partnerId="your-partner-id"
|
|
217
|
+
onLoginSuccess={(globalAccount) => {
|
|
218
|
+
console.log("Authenticated:", globalAccount);
|
|
61
219
|
}}
|
|
62
220
|
/>
|
|
63
221
|
</B3Provider>
|
|
@@ -65,281 +223,221 @@ function App() {
|
|
|
65
223
|
}
|
|
66
224
|
```
|
|
67
225
|
|
|
68
|
-
###
|
|
69
|
-
|
|
70
|
-
For enhanced security and user experience, you can use session keys with MetaMask:
|
|
226
|
+
### Session Key Authentication
|
|
71
227
|
|
|
72
228
|
```tsx
|
|
73
|
-
import { B3Provider, SignInWithB3 } from "@b3dotfun/sdk";
|
|
74
|
-
import B3DynamicModal from "@b3dotfun/sdk/components/B3DynamicModal";
|
|
75
|
-
import { useEffect, useState } from "react";
|
|
76
|
-
|
|
77
|
-
// Add Ethereum provider type declarations
|
|
78
|
-
declare global {
|
|
79
|
-
interface Window {
|
|
80
|
-
ethereum: {
|
|
81
|
-
request: (args: { method: string; params?: any[] }) => Promise<any>;
|
|
82
|
-
on: (event: string, listener: (...args: any[]) => void) => void;
|
|
83
|
-
removeListener: (event: string, listener: (...args: any[]) => void) => void;
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
229
|
+
import { B3Provider, SignInWithB3 } from "@b3dotfun/sdk/global-account/react";
|
|
87
230
|
|
|
88
|
-
// Define chain configuration
|
|
89
231
|
const b3Chain = {
|
|
90
232
|
id: 8333,
|
|
91
233
|
name: "B3",
|
|
92
|
-
nativeCurrency: {
|
|
93
|
-
|
|
94
|
-
symbol: "ETH",
|
|
95
|
-
decimals: 18
|
|
96
|
-
},
|
|
97
|
-
rpc: "https://mainnet-rpc.b3.fun",
|
|
98
|
-
icon: {
|
|
99
|
-
url: "https://cdn.b3.fun/b3-logo-white-circle.svg",
|
|
100
|
-
width: 32,
|
|
101
|
-
height: 32,
|
|
102
|
-
format: "svg"
|
|
103
|
-
},
|
|
104
|
-
blockExplorers: [
|
|
105
|
-
{
|
|
106
|
-
name: "B3 Explorer",
|
|
107
|
-
url: "https://explorer.b3.fun/"
|
|
108
|
-
}
|
|
109
|
-
]
|
|
234
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
235
|
+
rpc: "https://mainnet-rpc.b3.fun"
|
|
110
236
|
};
|
|
111
237
|
|
|
112
|
-
function
|
|
113
|
-
const [account, setAccount] = useState<string | null>(null);
|
|
114
|
-
|
|
115
|
-
useEffect(() => {
|
|
116
|
-
const connectToWallet = async () => {
|
|
117
|
-
if (typeof window.ethereum !== "undefined") {
|
|
118
|
-
try {
|
|
119
|
-
// Request account access
|
|
120
|
-
const accounts = await window.ethereum.request({ method: "eth_requestAccounts" });
|
|
121
|
-
setAccount(accounts[0]);
|
|
122
|
-
|
|
123
|
-
// Listen for account changes
|
|
124
|
-
const handleAccountsChanged = (accounts: string[]) => {
|
|
125
|
-
setAccount(accounts[0]);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
window.ethereum.on("accountsChanged", handleAccountsChanged);
|
|
129
|
-
|
|
130
|
-
return () => {
|
|
131
|
-
// Clean up listeners when component unmounts
|
|
132
|
-
if (window.ethereum) {
|
|
133
|
-
window.ethereum.removeListener("accountsChanged", handleAccountsChanged);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
} catch (error) {
|
|
137
|
-
console.error("Error connecting to wallet:", error);
|
|
138
|
-
}
|
|
139
|
-
} else {
|
|
140
|
-
console.error("No Ethereum wallet detected in browser");
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
connectToWallet();
|
|
145
|
-
}, []);
|
|
146
|
-
|
|
147
|
-
if (!account) {
|
|
148
|
-
return <div>Please connect your wallet</div>;
|
|
149
|
-
}
|
|
150
|
-
|
|
238
|
+
function SessionKeyAuth() {
|
|
151
239
|
return (
|
|
152
240
|
<B3Provider environment="production">
|
|
153
|
-
<
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
partnerId="YOUR_PARTNER_ID"
|
|
163
|
-
sessionKeyAddress={account as `0x${string}`}
|
|
164
|
-
onLoginSuccess={globalAccount => {
|
|
165
|
-
console.log("User authenticated with Global Account!", globalAccount);
|
|
166
|
-
}}
|
|
167
|
-
/>
|
|
168
|
-
</div>
|
|
169
|
-
</div>
|
|
241
|
+
<SignInWithB3
|
|
242
|
+
provider={{ strategy: "google" }}
|
|
243
|
+
chain={b3Chain}
|
|
244
|
+
partnerId="your-partner-id"
|
|
245
|
+
sessionKeyAddress="0x..." // MetaMask address
|
|
246
|
+
onLoginSuccess={(globalAccount) => {
|
|
247
|
+
console.log("Session key authenticated:", globalAccount);
|
|
248
|
+
}}
|
|
249
|
+
/>
|
|
170
250
|
</B3Provider>
|
|
171
251
|
);
|
|
172
252
|
}
|
|
173
253
|
```
|
|
174
254
|
|
|
175
|
-
###
|
|
255
|
+
### Permission Management
|
|
176
256
|
|
|
177
257
|
```tsx
|
|
178
|
-
import {
|
|
258
|
+
import { RequestPermissionsButton } from "@b3dotfun/sdk/global-account/react";
|
|
179
259
|
|
|
180
|
-
function
|
|
181
|
-
const { account } = useB3();
|
|
182
|
-
|
|
183
|
-
return <div>{!!account ? "User is logged in" : "User is not logged in"}</div>;
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### Using the Request Permissions Button
|
|
188
|
-
|
|
189
|
-
After authenticating with a session key, you can request specific permissions for smart contract interactions:
|
|
190
|
-
|
|
191
|
-
```tsx
|
|
192
|
-
import { RequestPermissionsButton } from "@b3dotfun/sdk";
|
|
193
|
-
|
|
194
|
-
// Define your chain configuration
|
|
195
|
-
const b3Chain = {
|
|
196
|
-
id: 8333,
|
|
197
|
-
name: "B3",
|
|
198
|
-
rpc: "https://mainnet-rpc.b3.fun"
|
|
199
|
-
// other chain properties
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
function RequestPermissionsExample({ sessionKeyAddress }) {
|
|
260
|
+
function PermissionsExample() {
|
|
203
261
|
return (
|
|
204
262
|
<RequestPermissionsButton
|
|
205
263
|
chain={b3Chain}
|
|
206
|
-
sessionKeyAddress=
|
|
207
|
-
onSuccess={() => {
|
|
208
|
-
console.log("Successfully requested permissions!");
|
|
209
|
-
}}
|
|
210
|
-
onError={error => {
|
|
211
|
-
console.error("Error requesting permissions:", error);
|
|
212
|
-
}}
|
|
264
|
+
sessionKeyAddress="0x..."
|
|
213
265
|
permissions={{
|
|
214
|
-
//
|
|
215
|
-
approvedTargets: ["0x06012c8cf97BEaD5deAe237070F9587f8E7A266d", "0xa8e42121e318e3D3BeD7f5969AF6D360045317DD"],
|
|
216
|
-
// Set validity period for the permissions
|
|
266
|
+
approvedTargets: ["0x..."], // Contract addresses
|
|
217
267
|
startDate: new Date(),
|
|
218
|
-
endDate: new Date(Date.now() +
|
|
268
|
+
endDate: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // 30 days
|
|
219
269
|
nativeTokenLimitPerTransaction: 0.0001
|
|
220
270
|
}}
|
|
271
|
+
onSuccess={() => console.log("Permissions granted")}
|
|
272
|
+
onError={(error) => console.error("Permission error:", error)}
|
|
221
273
|
/>
|
|
222
274
|
);
|
|
223
275
|
}
|
|
224
276
|
```
|
|
225
277
|
|
|
226
|
-
###
|
|
278
|
+
### Account Management
|
|
227
279
|
|
|
228
280
|
```tsx
|
|
229
|
-
import {
|
|
230
|
-
|
|
281
|
+
import { useB3 } from "@b3dotfun/sdk/global-account/react";
|
|
282
|
+
|
|
283
|
+
function AccountStatus() {
|
|
284
|
+
const { account, isAuthenticated } = useB3();
|
|
231
285
|
|
|
232
|
-
function App() {
|
|
233
286
|
return (
|
|
234
|
-
<
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
287
|
+
<div>
|
|
288
|
+
{isAuthenticated ? (
|
|
289
|
+
<p>Welcome, {account?.displayName}!</p>
|
|
290
|
+
) : (
|
|
291
|
+
<p>Please sign in</p>
|
|
292
|
+
)}
|
|
293
|
+
</div>
|
|
238
294
|
);
|
|
239
295
|
}
|
|
240
296
|
```
|
|
241
297
|
|
|
242
|
-
|
|
298
|
+
## Headless TypeScript Services
|
|
243
299
|
|
|
244
|
-
|
|
300
|
+
### Authentication Service
|
|
245
301
|
|
|
246
|
-
|
|
302
|
+
```typescript
|
|
303
|
+
import { authenticate, resetSocket } from "@b3dotfun/sdk/global-account/app";
|
|
247
304
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
305
|
+
// Authenticate with B3 Global Account
|
|
306
|
+
const authResult = await authenticate(
|
|
307
|
+
"access-token",
|
|
308
|
+
"identity-token",
|
|
309
|
+
{ /* additional params */ }
|
|
310
|
+
);
|
|
252
311
|
|
|
253
|
-
|
|
254
|
-
|
|
312
|
+
if (authResult) {
|
|
313
|
+
console.log("Authentication successful:", authResult);
|
|
314
|
+
} else {
|
|
315
|
+
console.log("Authentication failed");
|
|
255
316
|
}
|
|
317
|
+
|
|
318
|
+
// Reset socket connection
|
|
319
|
+
resetSocket();
|
|
256
320
|
```
|
|
257
321
|
|
|
258
|
-
|
|
322
|
+
### Basement Integration
|
|
259
323
|
|
|
260
|
-
```
|
|
261
|
-
import {
|
|
324
|
+
```typescript
|
|
325
|
+
import { authenticate as bsmntAuthenticate } from "@b3dotfun/sdk/global-account/bsmnt";
|
|
262
326
|
|
|
263
|
-
|
|
264
|
-
|
|
327
|
+
// Authenticate with Basement services
|
|
328
|
+
const bsmntAuth = await bsmntAuthenticate(
|
|
329
|
+
"access-token",
|
|
330
|
+
"identity-token"
|
|
331
|
+
);
|
|
332
|
+
```
|
|
265
333
|
|
|
266
|
-
|
|
267
|
-
setB3ModalOpen(true);
|
|
268
|
-
setB3ModalContentType({
|
|
269
|
-
type: "anySpend",
|
|
270
|
-
isMainnet: true
|
|
271
|
-
});
|
|
272
|
-
};
|
|
334
|
+
### React Native Support
|
|
273
335
|
|
|
274
|
-
|
|
275
|
-
|
|
336
|
+
```typescript
|
|
337
|
+
// For React Native applications
|
|
338
|
+
import { authenticate } from "@b3dotfun/sdk/global-account/app";
|
|
339
|
+
|
|
340
|
+
// Authentication works the same way
|
|
341
|
+
const result = await authenticate("access-token", "identity-token");
|
|
276
342
|
```
|
|
277
343
|
|
|
278
|
-
|
|
344
|
+
## Server-Side Usage
|
|
279
345
|
|
|
280
|
-
```
|
|
281
|
-
import {
|
|
282
|
-
import { useB3 } from "@b3dotfun/sdk";
|
|
346
|
+
```typescript
|
|
347
|
+
import { serverFunction } from "@b3dotfun/sdk/global-account/server";
|
|
283
348
|
|
|
284
|
-
|
|
285
|
-
|
|
349
|
+
// Server-side Global Account operations
|
|
350
|
+
// (Implementation depends on your specific needs)
|
|
351
|
+
```
|
|
286
352
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
353
|
+
# Shared Utilities
|
|
354
|
+
|
|
355
|
+
## Chain Management
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
import { supportedChains } from "@b3dotfun/sdk/shared/constants/chains/supported";
|
|
359
|
+
import { b3Chain } from "@b3dotfun/sdk/shared/constants/chains/b3Chain";
|
|
360
|
+
|
|
361
|
+
// Get supported chains
|
|
362
|
+
console.log(supportedChains);
|
|
363
|
+
|
|
364
|
+
// Use B3 chain configuration
|
|
365
|
+
console.log(b3Chain);
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
## Utility Functions
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
import { cn } from "@b3dotfun/sdk/shared/utils/cn";
|
|
372
|
+
|
|
373
|
+
// Tailwind class name utility
|
|
374
|
+
const classes = cn("base-class", "conditional-class", {
|
|
375
|
+
"active": isActive
|
|
376
|
+
});
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## Thirdweb Integration
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
import { thirdwebClient } from "@b3dotfun/sdk/shared/thirdweb/client";
|
|
383
|
+
|
|
384
|
+
// Pre-configured Thirdweb client
|
|
385
|
+
const client = thirdwebClient;
|
|
386
|
+
```
|
|
300
387
|
|
|
388
|
+
# Advanced Usage
|
|
389
|
+
|
|
390
|
+
## Modal System
|
|
391
|
+
|
|
392
|
+
```tsx
|
|
393
|
+
import { B3Provider } from "@b3dotfun/sdk/global-account/react";
|
|
394
|
+
import B3DynamicModal from "@b3dotfun/sdk/global-account/react/components/B3DynamicModal";
|
|
395
|
+
|
|
396
|
+
function App() {
|
|
301
397
|
return (
|
|
302
|
-
<
|
|
303
|
-
<
|
|
304
|
-
<
|
|
305
|
-
|
|
306
|
-
<p>
|
|
307
|
-
Price: {nftContract.price} {nftContract.currency.symbol}
|
|
308
|
-
</p>
|
|
309
|
-
|
|
310
|
-
<AnySpendNFTButton nftContract={nftContract} recipientAddress={account?.address} />
|
|
311
|
-
</div>
|
|
398
|
+
<B3Provider environment="production">
|
|
399
|
+
<YourApp />
|
|
400
|
+
<B3DynamicModal />
|
|
401
|
+
</B3Provider>
|
|
312
402
|
);
|
|
313
403
|
}
|
|
314
404
|
```
|
|
315
405
|
|
|
316
|
-
|
|
406
|
+
## Custom Styling
|
|
317
407
|
|
|
318
|
-
-
|
|
319
|
-
- Requesting necessary permissions
|
|
320
|
-
- Processing the transaction
|
|
321
|
-
- Handling success and error states
|
|
408
|
+
The SDK components support custom styling through CSS classes and CSS-in-JS solutions. All components are built with accessibility and customization in mind.
|
|
322
409
|
|
|
323
|
-
|
|
410
|
+
## TypeScript Support
|
|
324
411
|
|
|
325
|
-
|
|
412
|
+
All modules provide full TypeScript support with comprehensive type definitions:
|
|
326
413
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
- **AnySpend**: Components for cryptocurrency transactions
|
|
332
|
-
- **AnySpendNFT**: NFT-specific transaction component
|
|
414
|
+
```typescript
|
|
415
|
+
import type { Token } from "@b3dotfun/sdk/anyspend/types";
|
|
416
|
+
import type { GlobalAccount } from "@b3dotfun/sdk/global-account/types";
|
|
417
|
+
```
|
|
333
418
|
|
|
334
|
-
##
|
|
419
|
+
## Environment Configuration
|
|
335
420
|
|
|
336
|
-
|
|
421
|
+
```typescript
|
|
422
|
+
// Set environment variables
|
|
423
|
+
process.env.NEXT_PUBLIC_B3_API = "https://api.b3.fun";
|
|
424
|
+
process.env.NEXT_PUBLIC_BSMNT_API = "https://api.basement.fun";
|
|
425
|
+
```
|
|
337
426
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
427
|
+
## Error Handling
|
|
428
|
+
|
|
429
|
+
All services include proper error handling and type-safe responses:
|
|
430
|
+
|
|
431
|
+
```typescript
|
|
432
|
+
try {
|
|
433
|
+
const result = await anyspendService.getQuote(true, quoteRequest);
|
|
434
|
+
// Handle success
|
|
435
|
+
} catch (error) {
|
|
436
|
+
// Handle error
|
|
437
|
+
console.error("Quote failed:", error);
|
|
438
|
+
}
|
|
345
439
|
```
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
For more detailed examples and advanced usage patterns, refer to the individual module documentation and type definitions.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./react/hooks";
|
|
2
|
+
export * from "./react/providers/AnyspendProvider";
|
|
3
|
+
export * from "./types";
|
|
4
|
+
export * from "./utils/address";
|
|
5
|
+
export * from "./utils/chain";
|
|
6
|
+
export * from "./utils/format";
|
|
7
|
+
export * from "./utils/json";
|
|
8
|
+
export * from "./utils/number";
|
|
9
|
+
export * from "./utils/string";
|
|
10
|
+
export * from "./utils/token";
|
|
11
|
+
export * from "./constants";
|
|
12
|
+
export * from "./abis/abi-usdc-base";
|
|
13
|
+
export * from "./abis/erc20-staking";
|