@b3dotfun/sdk 0.0.1-alpha.18 → 0.0.1-alpha.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 +230 -328
- package/dist/cjs/anyspend/react/components/AnySpend.d.ts +1 -2
- package/dist/cjs/anyspend/react/components/AnySpend.js +4 -4
- package/dist/cjs/anyspend/react/components/AnySpendBuySpin.d.ts +1 -2
- package/dist/cjs/anyspend/react/components/AnySpendBuySpin.js +50 -123
- package/dist/cjs/anyspend/react/components/common/OrderHistoryItem.js +1 -5
- package/dist/cjs/anyspend/react/components/common/TokenBalance.js +1 -1
- package/dist/cjs/anyspend/utils/chain.js +0 -3
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +2 -2
- package/dist/{esm/global-account/react/components/B3Provider → cjs/global-account/react/components}/B3Provider.d.ts +29 -3
- package/dist/cjs/global-account/react/components/{B3Provider/B3Provider.js → B3Provider.js} +34 -6
- package/dist/cjs/global-account/react/components/{B3Provider/B3Provider.native.d.ts → B3Provider.native.d.ts} +25 -2
- package/dist/cjs/global-account/react/components/{B3Provider/B3Provider.native.js → B3Provider.native.js} +28 -5
- package/dist/cjs/global-account/react/components/StyleRoot.js +2 -2
- package/dist/cjs/global-account/react/components/index.d.ts +6 -8
- package/dist/cjs/global-account/react/components/index.js +16 -18
- package/dist/cjs/global-account/react/hooks/index.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/index.js +1 -2
- 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/stores/useModalStore.d.ts +0 -2
- 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 +7 -8
- package/dist/cjs/shared/constants/chains/supported.js +1 -8
- package/dist/cjs/shared/utils/chains.js +0 -4
- package/dist/cjs/shared/utils/number.js +1 -1
- package/dist/cjs/styles/index.d.ts +20 -0
- package/dist/cjs/styles/index.js +22 -0
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +1 -2
- package/dist/esm/anyspend/react/components/AnySpend.js +4 -4
- package/dist/esm/anyspend/react/components/AnySpendBuySpin.d.ts +1 -2
- package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +50 -123
- package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +1 -5
- package/dist/esm/anyspend/react/components/common/TokenBalance.js +1 -1
- package/dist/esm/anyspend/utils/chain.js +0 -3
- package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -1
- package/dist/{cjs/global-account/react/components/B3Provider → esm/global-account/react/components}/B3Provider.d.ts +29 -3
- package/dist/esm/global-account/react/components/{B3Provider/B3Provider.js → B3Provider.js} +32 -5
- package/dist/esm/global-account/react/components/{B3Provider/B3Provider.native.d.ts → B3Provider.native.d.ts} +25 -2
- package/dist/esm/global-account/react/components/{B3Provider/B3Provider.native.js → B3Provider.native.js} +26 -5
- package/dist/esm/global-account/react/components/StyleRoot.js +1 -1
- package/dist/esm/global-account/react/components/index.d.ts +6 -8
- package/dist/esm/global-account/react/components/index.js +5 -7
- 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/stores/useModalStore.d.ts +0 -2
- 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 +7 -8
- package/dist/esm/shared/constants/chains/supported.js +0 -7
- package/dist/esm/shared/utils/chains.js +0 -4
- package/dist/esm/shared/utils/number.js +1 -1
- package/dist/esm/styles/index.d.ts +20 -0
- package/dist/esm/styles/index.js +20 -0
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/AnySpend.d.ts +1 -2
- package/dist/types/anyspend/react/components/AnySpendBuySpin.d.ts +1 -2
- package/dist/types/global-account/react/components/{B3Provider/B3Provider.d.ts → B3Provider.d.ts} +28 -2
- package/dist/types/global-account/react/components/{B3Provider/B3Provider.native.d.ts → B3Provider.native.d.ts} +24 -1
- package/dist/types/global-account/react/components/index.d.ts +6 -8
- package/dist/types/global-account/react/hooks/index.d.ts +1 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +0 -2
- 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 +7 -8
- package/dist/types/styles/index.d.ts +20 -0
- package/package.json +24 -26
- package/src/anyspend/react/components/AnySpend.tsx +5 -6
- package/src/anyspend/react/components/AnySpendBuySpin.tsx +179 -232
- package/src/anyspend/react/components/common/OrderHistoryItem.tsx +1 -5
- package/src/anyspend/react/components/common/TokenBalance.tsx +1 -1
- package/src/anyspend/utils/chain.ts +0 -3
- package/src/global-account/react/components/B3DynamicModal.tsx +1 -1
- package/src/global-account/react/components/{B3Provider/B3Provider.native.tsx → B3Provider.native.tsx} +45 -4
- package/src/global-account/react/components/{B3Provider/B3Provider.tsx → B3Provider.tsx} +53 -4
- package/src/global-account/react/components/StyleRoot.tsx +1 -1
- package/src/global-account/react/components/index.ts +6 -8
- 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/stores/useModalStore.ts +0 -2
- package/src/shared/constants/chains/supported.ts +4 -12
- package/src/shared/utils/chains.ts +1 -4
- package/src/shared/utils/number.ts +1 -1
- package/src/styles/index.ts +24 -0
- package/dist/cjs/anyspend/index.native.d.ts +0 -13
- package/dist/cjs/anyspend/index.native.js +0 -35
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +0 -25
- package/dist/cjs/global-account/react/components/B3Provider/types.js +0 -20
- package/dist/cjs/global-account/react/components/B3Provider/useB3.d.ts +0 -5
- package/dist/cjs/global-account/react/components/B3Provider/useB3.js +0 -17
- package/dist/cjs/global-account/react/index.native.d.ts +0 -7
- package/dist/cjs/global-account/react/index.native.js +0 -21
- package/dist/esm/anyspend/index.native.d.ts +0 -13
- package/dist/esm/anyspend/index.native.js +0 -19
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +0 -25
- package/dist/esm/global-account/react/components/B3Provider/types.js +0 -17
- package/dist/esm/global-account/react/components/B3Provider/useB3.d.ts +0 -5
- package/dist/esm/global-account/react/components/B3Provider/useB3.js +0 -14
- package/dist/esm/global-account/react/index.native.d.ts +0 -7
- package/dist/esm/global-account/react/index.native.js +0 -11
- package/dist/types/anyspend/index.native.d.ts +0 -13
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +0 -25
- package/dist/types/global-account/react/components/B3Provider/useB3.d.ts +0 -5
- package/dist/types/global-account/react/index.native.d.ts +0 -7
- package/src/anyspend/index.native.ts +0 -24
- package/src/global-account/react/components/B3Provider/types.ts +0 -40
- package/src/global-account/react/components/B3Provider/useB3.ts +0 -17
- package/src/global-account/react/index.native.ts +0 -14
package/README.md
CHANGED
|
@@ -1,30 +1,13 @@
|
|
|
1
1
|
# @b3dotfun/sdk
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A React component library for Anyspend & B3 Global Accounts. Includes integration with web & mobile applications, providing easy-to-use components for Web3 transactions, Web3 authentication, wallet management, and blockchain interactions & more.
|
|
4
4
|
|
|
5
|
-
##
|
|
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
|
|
5
|
+
## Current compatibility
|
|
22
6
|
|
|
23
7
|
| Feature | React Web | React Native |
|
|
24
8
|
| ---------------------- | --------- | ------------ |
|
|
25
9
|
| AnySpend | ✅ | ❌ |
|
|
26
|
-
| Global Accounts
|
|
27
|
-
| Headless Services | ✅ | ✅ |
|
|
10
|
+
| Global Accounts (beta) | ✅ | ✅ |
|
|
28
11
|
|
|
29
12
|
## Installation
|
|
30
13
|
|
|
@@ -36,186 +19,45 @@ yarn add @b3dotfun/sdk
|
|
|
36
19
|
pnpm add @b3dotfun/sdk
|
|
37
20
|
```
|
|
38
21
|
|
|
39
|
-
##
|
|
22
|
+
## Features
|
|
40
23
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```
|
|
24
|
+
- **[Anyspend](#anyspend)**: A React SDK for integrating with the Anyspend protocol, providing hooks and utilities for cross-chain swaps, NFT minting, and other blockchain operations.
|
|
25
|
+
- **[Global Accounts](#global-accounts)**: B3 Global Accounts allow for seamlessly authenticating and transaction in our ecosystem, using the same account throughout the entire experience.
|
|
44
26
|
|
|
45
27
|
# AnySpend
|
|
46
28
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
## React Components
|
|
50
|
-
|
|
51
|
-
### Basic Cross-Chain Swap
|
|
52
|
-
|
|
53
|
-
```tsx
|
|
54
|
-
import { AnySpend } from "@b3dotfun/sdk/anyspend/react";
|
|
29
|
+
Documentation coming soon.
|
|
55
30
|
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<AnySpend
|
|
59
|
-
isMainnet={true}
|
|
60
|
-
mode="page"
|
|
61
|
-
/>
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### NFT Minting
|
|
67
|
-
|
|
68
|
-
```tsx
|
|
69
|
-
import { AnySpendNFTButton } from "@b3dotfun/sdk/anyspend/react";
|
|
31
|
+
# Global Accounts
|
|
70
32
|
|
|
71
|
-
|
|
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
|
-
};
|
|
33
|
+
## Usage
|
|
84
34
|
|
|
85
|
-
|
|
86
|
-
<AnySpendNFTButton
|
|
87
|
-
nftContract={nftContract}
|
|
88
|
-
recipientAddress="0x..."
|
|
89
|
-
/>
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
```
|
|
35
|
+
### Basic Setup
|
|
93
36
|
|
|
94
|
-
|
|
37
|
+
Wrap your application with the `B3Provider`:
|
|
95
38
|
|
|
96
39
|
```tsx
|
|
97
|
-
import {
|
|
40
|
+
import { B3Provider } from "@b3dotfun/sdk";
|
|
41
|
+
import "@b3dotfun/sdk/styles"; // Import default styles
|
|
98
42
|
|
|
99
43
|
function App() {
|
|
100
|
-
return
|
|
101
|
-
<AnyspendProvider isMainnet={true}>
|
|
102
|
-
<YourAnySpendComponents />
|
|
103
|
-
</AnyspendProvider>
|
|
104
|
-
);
|
|
44
|
+
return <B3Provider environment="production">{/* Your app content */}</B3Provider>;
|
|
105
45
|
}
|
|
106
46
|
```
|
|
107
47
|
|
|
108
|
-
|
|
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
|
|
48
|
+
### Authentication with SignInWithB3
|
|
207
49
|
|
|
208
50
|
```tsx
|
|
209
|
-
import {
|
|
51
|
+
import { SignInWithB3, B3Provider } from "@b3dotfun/sdk";
|
|
210
52
|
|
|
211
53
|
function App() {
|
|
212
54
|
return (
|
|
213
55
|
<B3Provider environment="production">
|
|
214
56
|
<SignInWithB3
|
|
215
|
-
|
|
216
|
-
partnerId="
|
|
217
|
-
onLoginSuccess={
|
|
218
|
-
console.log("
|
|
57
|
+
strategies={["google"]}
|
|
58
|
+
partnerId="YOUR_PARTNER_ID"
|
|
59
|
+
onLoginSuccess={globalAccount => {
|
|
60
|
+
console.log("User authenticated with Global Account!", globalAccount);
|
|
219
61
|
}}
|
|
220
62
|
/>
|
|
221
63
|
</B3Provider>
|
|
@@ -223,221 +65,281 @@ function App() {
|
|
|
223
65
|
}
|
|
224
66
|
```
|
|
225
67
|
|
|
226
|
-
### Session
|
|
68
|
+
### Using Session Keys
|
|
69
|
+
|
|
70
|
+
For enhanced security and user experience, you can use session keys with MetaMask:
|
|
227
71
|
|
|
228
72
|
```tsx
|
|
229
|
-
import { B3Provider, SignInWithB3 } from "@b3dotfun/sdk
|
|
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
|
+
}
|
|
230
87
|
|
|
88
|
+
// Define chain configuration
|
|
231
89
|
const b3Chain = {
|
|
232
90
|
id: 8333,
|
|
233
91
|
name: "B3",
|
|
234
|
-
nativeCurrency: {
|
|
235
|
-
|
|
92
|
+
nativeCurrency: {
|
|
93
|
+
name: "Ether",
|
|
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
|
+
]
|
|
236
110
|
};
|
|
237
111
|
|
|
238
|
-
function
|
|
112
|
+
function App() {
|
|
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
|
+
|
|
239
151
|
return (
|
|
240
152
|
<B3Provider environment="production">
|
|
241
|
-
<
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
153
|
+
<B3DynamicModal />
|
|
154
|
+
<div className="flex min-h-screen items-center justify-center bg-white">
|
|
155
|
+
<div className="text-center">
|
|
156
|
+
<h1 className="mb-6 text-3xl font-bold">B3 Authentication Example</h1>
|
|
157
|
+
<SignInWithB3
|
|
158
|
+
provider={{
|
|
159
|
+
strategy: "google"
|
|
160
|
+
}}
|
|
161
|
+
chain={b3Chain}
|
|
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>
|
|
250
170
|
</B3Provider>
|
|
251
171
|
);
|
|
252
172
|
}
|
|
253
173
|
```
|
|
254
174
|
|
|
255
|
-
###
|
|
175
|
+
### Accessing B3 Context
|
|
256
176
|
|
|
257
177
|
```tsx
|
|
258
|
-
import {
|
|
178
|
+
import { useB3 } from "@b3dotfun/sdk";
|
|
259
179
|
|
|
260
|
-
function
|
|
180
|
+
function MyComponent() {
|
|
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 }) {
|
|
261
203
|
return (
|
|
262
204
|
<RequestPermissionsButton
|
|
263
205
|
chain={b3Chain}
|
|
264
|
-
sessionKeyAddress=
|
|
206
|
+
sessionKeyAddress={sessionKeyAddress}
|
|
207
|
+
onSuccess={() => {
|
|
208
|
+
console.log("Successfully requested permissions!");
|
|
209
|
+
}}
|
|
210
|
+
onError={error => {
|
|
211
|
+
console.error("Error requesting permissions:", error);
|
|
212
|
+
}}
|
|
265
213
|
permissions={{
|
|
266
|
-
|
|
214
|
+
// Specify contract addresses that the session key can interact with
|
|
215
|
+
approvedTargets: ["0x06012c8cf97BEaD5deAe237070F9587f8E7A266d", "0xa8e42121e318e3D3BeD7f5969AF6D360045317DD"],
|
|
216
|
+
// Set validity period for the permissions
|
|
267
217
|
startDate: new Date(),
|
|
268
|
-
endDate: new Date(Date.now() +
|
|
218
|
+
endDate: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30), // 30 days
|
|
269
219
|
nativeTokenLimitPerTransaction: 0.0001
|
|
270
220
|
}}
|
|
271
|
-
onSuccess={() => console.log("Permissions granted")}
|
|
272
|
-
onError={(error) => console.error("Permission error:", error)}
|
|
273
221
|
/>
|
|
274
222
|
);
|
|
275
223
|
}
|
|
276
224
|
```
|
|
277
225
|
|
|
278
|
-
###
|
|
226
|
+
### Using the Modal System
|
|
279
227
|
|
|
280
228
|
```tsx
|
|
281
|
-
import {
|
|
282
|
-
|
|
283
|
-
function AccountStatus() {
|
|
284
|
-
const { account, isAuthenticated } = useB3();
|
|
229
|
+
import { B3Provider } from "@b3dotfun/sdk";
|
|
230
|
+
import B3DynamicModal from "@b3dotfun/sdk/components/B3DynamicModal";
|
|
285
231
|
|
|
232
|
+
function App() {
|
|
286
233
|
return (
|
|
287
|
-
<
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
<p>Please sign in</p>
|
|
292
|
-
)}
|
|
293
|
-
</div>
|
|
234
|
+
<B3Provider environment="production">
|
|
235
|
+
<YourApp />
|
|
236
|
+
<B3DynamicModal />
|
|
237
|
+
</B3Provider>
|
|
294
238
|
);
|
|
295
239
|
}
|
|
296
240
|
```
|
|
297
241
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
### Authentication Service
|
|
301
|
-
|
|
302
|
-
```typescript
|
|
303
|
-
import { authenticate, resetSocket } from "@b3dotfun/sdk/global-account/app";
|
|
304
|
-
|
|
305
|
-
// Authenticate with B3 Global Account
|
|
306
|
-
const authResult = await authenticate(
|
|
307
|
-
"access-token",
|
|
308
|
-
"identity-token",
|
|
309
|
-
{ /* additional params */ }
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
if (authResult) {
|
|
313
|
-
console.log("Authentication successful:", authResult);
|
|
314
|
-
} else {
|
|
315
|
-
console.log("Authentication failed");
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
// Reset socket connection
|
|
319
|
-
resetSocket();
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
### Basement Integration
|
|
242
|
+
### Cross-chain swap, minting NFTs, and more with AnySpend
|
|
323
243
|
|
|
324
|
-
|
|
325
|
-
import { authenticate as bsmntAuthenticate } from "@b3dotfun/sdk/global-account/bsmnt";
|
|
244
|
+
AnySpend components simplify cross-chain swaps, NFT minting, and other blockchain operations.
|
|
326
245
|
|
|
327
|
-
|
|
328
|
-
const bsmntAuth = await bsmntAuthenticate(
|
|
329
|
-
"access-token",
|
|
330
|
-
"identity-token"
|
|
331
|
-
);
|
|
332
|
-
```
|
|
246
|
+
### Cross-chain swap example
|
|
333
247
|
|
|
334
|
-
|
|
248
|
+
#### Page mode
|
|
335
249
|
|
|
336
|
-
```
|
|
337
|
-
|
|
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");
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
## Server-Side Usage
|
|
345
|
-
|
|
346
|
-
```typescript
|
|
347
|
-
import { serverFunction } from "@b3dotfun/sdk/global-account/server";
|
|
250
|
+
```tsx
|
|
251
|
+
import { AnySpend } from "@b3dotfun/sdk";
|
|
348
252
|
|
|
349
|
-
|
|
350
|
-
|
|
253
|
+
function CrossChainSwapExample() {
|
|
254
|
+
return <AnySpend isMainnet={true} mode="page" />;
|
|
255
|
+
}
|
|
351
256
|
```
|
|
352
257
|
|
|
353
|
-
|
|
258
|
+
#### Modal mode
|
|
354
259
|
|
|
355
|
-
|
|
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
|
-
```
|
|
260
|
+
```tsx
|
|
261
|
+
import { AnySpend } from "@b3dotfun/sdk";
|
|
367
262
|
|
|
368
|
-
|
|
263
|
+
function CrossChainSwapExample() {
|
|
264
|
+
const { setB3ModalOpen, setB3ModalContentType } = useModalStore();
|
|
369
265
|
|
|
370
|
-
|
|
371
|
-
|
|
266
|
+
const handleClick = () => {
|
|
267
|
+
setB3ModalOpen(true);
|
|
268
|
+
setB3ModalContentType({
|
|
269
|
+
type: "anySpend",
|
|
270
|
+
isMainnet: true
|
|
271
|
+
});
|
|
272
|
+
};
|
|
372
273
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
"active": isActive
|
|
376
|
-
});
|
|
274
|
+
return <button onClick={handleClick}>Cross-chain swap</button>;
|
|
275
|
+
}
|
|
377
276
|
```
|
|
378
277
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
```typescript
|
|
382
|
-
import { thirdwebClient } from "@b3dotfun/sdk/shared/thirdweb/client";
|
|
383
|
-
|
|
384
|
-
// Pre-configured Thirdweb client
|
|
385
|
-
const client = thirdwebClient;
|
|
386
|
-
```
|
|
278
|
+
### NFT minting example
|
|
387
279
|
|
|
388
|
-
|
|
280
|
+
```tsx
|
|
281
|
+
import { AnySpendNFTButton } from "@b3dotfun/sdk/anyspend/react";
|
|
282
|
+
import { useB3 } from "@b3dotfun/sdk";
|
|
389
283
|
|
|
390
|
-
|
|
284
|
+
function NFTMintingExample() {
|
|
285
|
+
const { account } = useB3();
|
|
391
286
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
287
|
+
// Define your NFT contract details
|
|
288
|
+
const nftContract = {
|
|
289
|
+
address: "0x9c275ff1634519E9B5449ec79cd939B5F900564d", // NFT contract address
|
|
290
|
+
chainId: 8333, // B3 chain ID
|
|
291
|
+
name: "Example NFT Collection",
|
|
292
|
+
imageUrl: "https://example.com/nft-image.jpg",
|
|
293
|
+
description: "A beautiful NFT from our collection",
|
|
294
|
+
price: "1000000000000000000", // Price in wei (1 ETH)
|
|
295
|
+
currency: {
|
|
296
|
+
symbol: "ETH",
|
|
297
|
+
decimals: 18
|
|
298
|
+
}
|
|
299
|
+
};
|
|
395
300
|
|
|
396
|
-
function App() {
|
|
397
301
|
return (
|
|
398
|
-
<
|
|
399
|
-
<
|
|
400
|
-
<
|
|
401
|
-
|
|
302
|
+
<div className="nft-card">
|
|
303
|
+
<img src={nftContract.imageUrl} alt={nftContract.name} />
|
|
304
|
+
<h3>{nftContract.name}</h3>
|
|
305
|
+
<p>{nftContract.description}</p>
|
|
306
|
+
<p>
|
|
307
|
+
Price: {nftContract.price} {nftContract.currency.symbol}
|
|
308
|
+
</p>
|
|
309
|
+
|
|
310
|
+
<AnySpendNFTButton nftContract={nftContract} recipientAddress={account?.address} />
|
|
311
|
+
</div>
|
|
402
312
|
);
|
|
403
313
|
}
|
|
404
314
|
```
|
|
405
315
|
|
|
406
|
-
|
|
407
|
-
|
|
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.
|
|
316
|
+
The `AnySpendNFTButton` component handles the entire minting process, including:
|
|
409
317
|
|
|
410
|
-
|
|
318
|
+
- Checking wallet connection
|
|
319
|
+
- Requesting necessary permissions
|
|
320
|
+
- Processing the transaction
|
|
321
|
+
- Handling success and error states
|
|
411
322
|
|
|
412
|
-
|
|
323
|
+
You can customize the appearance and behavior of the button using standard React props.
|
|
413
324
|
|
|
414
|
-
|
|
415
|
-
import type { Token } from "@b3dotfun/sdk/anyspend/types";
|
|
416
|
-
import type { GlobalAccount } from "@b3dotfun/sdk/global-account/types";
|
|
417
|
-
```
|
|
325
|
+
## Components
|
|
418
326
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
```
|
|
327
|
+
- **SignInWithB3**: Authentication component with multiple provider options
|
|
328
|
+
- **B3Provider**: Context provider for B3 services
|
|
329
|
+
- **B3DynamicModal**: Dynamic modal system for B3 interactions
|
|
330
|
+
- **RequestPermissionsButton**: Component to request permissions for session keys
|
|
331
|
+
- **AnySpend**: Components for cryptocurrency transactions
|
|
332
|
+
- **AnySpendNFT**: NFT-specific transaction component
|
|
426
333
|
|
|
427
|
-
##
|
|
334
|
+
## Advanced Configuration
|
|
428
335
|
|
|
429
|
-
|
|
336
|
+
The `B3Provider` accepts several configuration options:
|
|
430
337
|
|
|
431
|
-
```
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
//
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
338
|
+
```tsx
|
|
339
|
+
<B3Provider
|
|
340
|
+
environment="production" // or "development"
|
|
341
|
+
// Additional config options as needed
|
|
342
|
+
>
|
|
343
|
+
{children}
|
|
344
|
+
</B3Provider>
|
|
439
345
|
```
|
|
440
|
-
|
|
441
|
-
---
|
|
442
|
-
|
|
443
|
-
For more detailed examples and advanced usage patterns, refer to the individual module documentation and type definitions.
|
|
@@ -11,7 +11,7 @@ export declare enum PanelView {
|
|
|
11
11
|
LOADING = 3,
|
|
12
12
|
FIAT_PAYMENT = 4
|
|
13
13
|
}
|
|
14
|
-
export declare function AnySpend({ destinationTokenAddress, destinationTokenChainId, isMainnet, mode, defaultActiveTab, loadOrder, hideTransactionHistoryButton
|
|
14
|
+
export declare function AnySpend({ destinationTokenAddress, destinationTokenChainId, isMainnet, mode, defaultActiveTab, loadOrder, hideTransactionHistoryButton }: {
|
|
15
15
|
destinationTokenAddress?: string;
|
|
16
16
|
destinationTokenChainId?: number;
|
|
17
17
|
isMainnet?: boolean;
|
|
@@ -19,5 +19,4 @@ export declare function AnySpend({ destinationTokenAddress, destinationTokenChai
|
|
|
19
19
|
defaultActiveTab?: "crypto" | "fiat";
|
|
20
20
|
loadOrder?: string;
|
|
21
21
|
hideTransactionHistoryButton?: boolean;
|
|
22
|
-
recipientAddress?: string;
|
|
23
22
|
}): import("react/jsx-runtime").JSX.Element;
|