uvd-x402-sdk 2.0.3 → 2.2.0
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 +282 -15
- package/dist/adapters/index.d.mts +139 -0
- package/dist/adapters/index.d.ts +139 -0
- package/dist/adapters/index.js +724 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/index.mjs +720 -0
- package/dist/adapters/index.mjs.map +1 -0
- package/dist/{index-MTBgC_SL.d.mts → index-BHwtdJrt.d.mts} +45 -4
- package/dist/{index-MTBgC_SL.d.ts → index-BHwtdJrt.d.ts} +45 -4
- package/dist/{index-Db8dWNam.d.ts → index-CkDdnSNx.d.mts} +33 -2
- package/dist/{index-D0N_SYpK.d.mts → index-UTj85ZDJ.d.ts} +33 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +210 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +207 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/evm/index.d.mts +19 -3
- package/dist/providers/evm/index.d.ts +19 -3
- package/dist/providers/evm/index.js +228 -12
- package/dist/providers/evm/index.js.map +1 -1
- package/dist/providers/evm/index.mjs +228 -12
- package/dist/providers/evm/index.mjs.map +1 -1
- package/dist/providers/near/index.d.mts +1 -1
- package/dist/providers/near/index.d.ts +1 -1
- package/dist/providers/near/index.js.map +1 -1
- package/dist/providers/near/index.mjs.map +1 -1
- package/dist/providers/solana/index.d.mts +1 -1
- package/dist/providers/solana/index.d.ts +1 -1
- package/dist/providers/solana/index.js +168 -0
- package/dist/providers/solana/index.js.map +1 -1
- package/dist/providers/solana/index.mjs +168 -0
- package/dist/providers/solana/index.mjs.map +1 -1
- package/dist/providers/stellar/index.d.mts +1 -1
- package/dist/providers/stellar/index.d.ts +1 -1
- package/dist/providers/stellar/index.js.map +1 -1
- package/dist/providers/stellar/index.mjs.map +1 -1
- package/dist/react/index.d.mts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +168 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +168 -0
- package/dist/react/index.mjs.map +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +168 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +168 -0
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +10 -2
- package/src/adapters/index.ts +13 -0
- package/src/adapters/wagmi.ts +294 -0
- package/src/chains/index.ts +255 -1
- package/src/index.ts +9 -0
- package/src/providers/evm/index.ts +64 -16
- package/src/types/index.ts +46 -3
package/README.md
CHANGED
|
@@ -2,17 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
> Gasless crypto payments across 14 blockchain networks using the x402 protocol.
|
|
4
4
|
|
|
5
|
-
The x402 SDK enables any application to accept
|
|
5
|
+
The x402 SDK enables any application to accept stablecoin payments (USDC, EURC, AUSD, PYUSD, GHO, crvUSD) without requiring users to pay gas fees. Users sign a message or transaction, and the Ultravioleta facilitator handles on-chain settlement.
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
9
|
- **14 Supported Networks**: EVM chains, Solana, Fogo, Stellar, and NEAR
|
|
10
|
+
- **Multi-Stablecoin**: USDC, EURC, AUSD, PYUSD, GHO, crvUSD support on EVM chains
|
|
10
11
|
- **x402 v1 & v2**: Full support for both protocol versions with automatic detection
|
|
11
12
|
- **Gasless Payments**: Users never pay gas - the facilitator covers all network fees
|
|
12
13
|
- **Multi-Network**: Accept payments on multiple networks simultaneously
|
|
13
14
|
- **Type-Safe**: Comprehensive TypeScript definitions
|
|
14
15
|
- **Framework Agnostic**: Works with any JavaScript framework
|
|
15
16
|
- **React Hooks**: First-class React integration
|
|
17
|
+
- **Wagmi/RainbowKit**: Dedicated adapter for wagmi-based apps
|
|
16
18
|
- **Modular**: Import only what you need
|
|
17
19
|
|
|
18
20
|
## Quick Start
|
|
@@ -126,6 +128,117 @@ const result = await client.createPayment({
|
|
|
126
128
|
|
|
127
129
|
---
|
|
128
130
|
|
|
131
|
+
## Wagmi / RainbowKit Integration
|
|
132
|
+
|
|
133
|
+
If you're using wagmi with RainbowKit, ConnectKit, or other wagmi-based wallet libraries, use the dedicated wagmi adapter:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { useWalletClient } from 'wagmi';
|
|
137
|
+
import { createPaymentFromWalletClient } from 'uvd-x402-sdk/wagmi';
|
|
138
|
+
|
|
139
|
+
function PayButton() {
|
|
140
|
+
const { data: walletClient } = useWalletClient();
|
|
141
|
+
|
|
142
|
+
const handlePay = async () => {
|
|
143
|
+
const paymentHeader = await createPaymentFromWalletClient(walletClient, {
|
|
144
|
+
recipient: '0xD3868E1eD738CED6945A574a7c769433BeD5d474',
|
|
145
|
+
amount: '10.00',
|
|
146
|
+
chainName: 'base', // optional, defaults to 'base'
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Use in your API request
|
|
150
|
+
await fetch('/api/purchase', {
|
|
151
|
+
headers: { 'X-PAYMENT': paymentHeader },
|
|
152
|
+
method: 'POST',
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
return <button onClick={handlePay}>Pay $10 USDC</button>;
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### With the Helper Hook
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { useWalletClient } from 'wagmi';
|
|
164
|
+
import { useX402Wagmi } from 'uvd-x402-sdk/wagmi';
|
|
165
|
+
|
|
166
|
+
function PayButton() {
|
|
167
|
+
const { data: walletClient } = useWalletClient();
|
|
168
|
+
const { createPayment, isReady } = useX402Wagmi(walletClient);
|
|
169
|
+
|
|
170
|
+
const handlePay = async () => {
|
|
171
|
+
const paymentHeader = await createPayment({
|
|
172
|
+
recipient: '0xD3868E1eD738CED6945A574a7c769433BeD5d474',
|
|
173
|
+
amount: '10.00',
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
await fetch('/api/purchase', {
|
|
177
|
+
headers: { 'X-PAYMENT': paymentHeader },
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<button onClick={handlePay} disabled={!isReady}>
|
|
183
|
+
Pay $10 USDC
|
|
184
|
+
</button>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Full Example with RainbowKit
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
import { ConnectButton } from '@rainbow-me/rainbowkit';
|
|
193
|
+
import { useWalletClient, useAccount } from 'wagmi';
|
|
194
|
+
import { createPaymentFromWalletClient } from 'uvd-x402-sdk/wagmi';
|
|
195
|
+
|
|
196
|
+
function App() {
|
|
197
|
+
const { data: walletClient } = useWalletClient();
|
|
198
|
+
const { isConnected } = useAccount();
|
|
199
|
+
|
|
200
|
+
const handlePurchase = async () => {
|
|
201
|
+
if (!walletClient) return;
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
const paymentHeader = await createPaymentFromWalletClient(walletClient, {
|
|
205
|
+
recipient: '0xD3868E1eD738CED6945A574a7c769433BeD5d474',
|
|
206
|
+
amount: '5.00',
|
|
207
|
+
chainName: 'base',
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const response = await fetch('/api/purchase', {
|
|
211
|
+
method: 'POST',
|
|
212
|
+
headers: {
|
|
213
|
+
'Content-Type': 'application/json',
|
|
214
|
+
'X-PAYMENT': paymentHeader,
|
|
215
|
+
},
|
|
216
|
+
body: JSON.stringify({ item: 'premium-feature' }),
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
if (response.ok) {
|
|
220
|
+
alert('Purchase successful!');
|
|
221
|
+
}
|
|
222
|
+
} catch (error) {
|
|
223
|
+
console.error('Payment failed:', error);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<div>
|
|
229
|
+
<ConnectButton />
|
|
230
|
+
{isConnected && (
|
|
231
|
+
<button onClick={handlePurchase}>
|
|
232
|
+
Buy Premium ($5 USDC)
|
|
233
|
+
</button>
|
|
234
|
+
)}
|
|
235
|
+
</div>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
129
242
|
## Network Examples
|
|
130
243
|
|
|
131
244
|
### EVM Chains (10 Networks)
|
|
@@ -557,6 +670,118 @@ const options = generatePaymentOptions(chains, '10.00');
|
|
|
557
670
|
|
|
558
671
|
---
|
|
559
672
|
|
|
673
|
+
## Multi-Stablecoin Support (EVM)
|
|
674
|
+
|
|
675
|
+
EVM chains support multiple stablecoins beyond USDC. Token availability varies by chain.
|
|
676
|
+
|
|
677
|
+
### Supported Tokens
|
|
678
|
+
|
|
679
|
+
| Token | Description | Decimals | Chains |
|
|
680
|
+
|-------|-------------|----------|--------|
|
|
681
|
+
| USDC | USD Coin (Circle) | 6 | All EVM chains |
|
|
682
|
+
| EURC | Euro Coin (Circle) | 6 | Ethereum, Base, Avalanche |
|
|
683
|
+
| AUSD | Agora USD | 6 | Ethereum, Avalanche, Polygon, Arbitrum, Monad |
|
|
684
|
+
| PYUSD | PayPal USD | 6 | Ethereum |
|
|
685
|
+
| GHO | Aave GHO | 18 | Ethereum, Base, Arbitrum |
|
|
686
|
+
| crvUSD | Curve USD | 18 | Ethereum, Arbitrum |
|
|
687
|
+
|
|
688
|
+
### Basic Usage
|
|
689
|
+
|
|
690
|
+
```typescript
|
|
691
|
+
import { X402Client } from 'uvd-x402-sdk';
|
|
692
|
+
|
|
693
|
+
const client = new X402Client({ defaultChain: 'base' });
|
|
694
|
+
await client.connect('base');
|
|
695
|
+
|
|
696
|
+
// Pay with EURC instead of USDC
|
|
697
|
+
const result = await client.createPayment({
|
|
698
|
+
recipient: '0xD3868E1eD738CED6945A574a7c769433BeD5d474',
|
|
699
|
+
amount: '10.00',
|
|
700
|
+
tokenType: 'eurc', // 'usdc' | 'eurc' | 'ausd' | 'pyusd' | 'gho' | 'crvusd'
|
|
701
|
+
});
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
### Check Token Availability
|
|
705
|
+
|
|
706
|
+
```typescript
|
|
707
|
+
import {
|
|
708
|
+
getSupportedTokens,
|
|
709
|
+
isTokenSupported,
|
|
710
|
+
getTokenConfig,
|
|
711
|
+
getChainsByToken,
|
|
712
|
+
} from 'uvd-x402-sdk';
|
|
713
|
+
|
|
714
|
+
// Get all tokens supported on a chain
|
|
715
|
+
const tokens = getSupportedTokens('ethereum');
|
|
716
|
+
// Returns: ['usdc', 'eurc', 'ausd', 'pyusd', 'gho', 'crvusd']
|
|
717
|
+
|
|
718
|
+
const baseTokens = getSupportedTokens('base');
|
|
719
|
+
// Returns: ['usdc', 'eurc', 'gho']
|
|
720
|
+
|
|
721
|
+
// Check if a specific token is supported
|
|
722
|
+
if (isTokenSupported('base', 'eurc')) {
|
|
723
|
+
console.log('EURC available on Base');
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// Get token configuration (address, decimals, name)
|
|
727
|
+
const eurcConfig = getTokenConfig('ethereum', 'eurc');
|
|
728
|
+
// Returns: { address: '0x1aBa...', decimals: 6, name: 'EURC', version: '2' }
|
|
729
|
+
|
|
730
|
+
// Find all chains that support a token
|
|
731
|
+
const ghoChains = getChainsByToken('gho');
|
|
732
|
+
// Returns: [baseConfig, ethereumConfig, arbitrumConfig]
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
### Check Token Balance
|
|
736
|
+
|
|
737
|
+
```typescript
|
|
738
|
+
import { EVMProvider } from 'uvd-x402-sdk';
|
|
739
|
+
import { getChainByName } from 'uvd-x402-sdk';
|
|
740
|
+
|
|
741
|
+
const evm = new EVMProvider();
|
|
742
|
+
await evm.connect();
|
|
743
|
+
|
|
744
|
+
const chainConfig = getChainByName('ethereum')!;
|
|
745
|
+
|
|
746
|
+
// Check USDC balance (default)
|
|
747
|
+
const usdcBalance = await evm.getBalance(chainConfig);
|
|
748
|
+
|
|
749
|
+
// Check EURC balance
|
|
750
|
+
const eurcBalance = await evm.getBalance(chainConfig, 'eurc');
|
|
751
|
+
|
|
752
|
+
// Check GHO balance
|
|
753
|
+
const ghoBalance = await evm.getBalance(chainConfig, 'gho');
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
### Wagmi/RainbowKit with Multi-Token
|
|
757
|
+
|
|
758
|
+
```typescript
|
|
759
|
+
import { useWalletClient } from 'wagmi';
|
|
760
|
+
import { createPaymentFromWalletClient } from 'uvd-x402-sdk/wagmi';
|
|
761
|
+
|
|
762
|
+
function PayWithEURC() {
|
|
763
|
+
const { data: walletClient } = useWalletClient();
|
|
764
|
+
|
|
765
|
+
const handlePay = async () => {
|
|
766
|
+
const paymentHeader = await createPaymentFromWalletClient(walletClient, {
|
|
767
|
+
recipient: '0xD3868E1eD738CED6945A574a7c769433BeD5d474',
|
|
768
|
+
amount: '10.00',
|
|
769
|
+
chainName: 'base',
|
|
770
|
+
tokenType: 'eurc', // Pay with EURC
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
await fetch('/api/purchase', {
|
|
774
|
+
headers: { 'X-PAYMENT': paymentHeader },
|
|
775
|
+
method: 'POST',
|
|
776
|
+
});
|
|
777
|
+
};
|
|
778
|
+
|
|
779
|
+
return <button onClick={handlePay}>Pay 10 EURC</button>;
|
|
780
|
+
}
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
---
|
|
784
|
+
|
|
560
785
|
## React Integration
|
|
561
786
|
|
|
562
787
|
```tsx
|
|
@@ -612,18 +837,18 @@ function PaymentPage() {
|
|
|
612
837
|
|
|
613
838
|
### EVM Networks (10)
|
|
614
839
|
|
|
615
|
-
| Network | Chain ID |
|
|
616
|
-
|
|
617
|
-
|
|
|
618
|
-
|
|
|
619
|
-
|
|
|
620
|
-
| Arbitrum | 42161 |
|
|
621
|
-
|
|
|
622
|
-
|
|
|
623
|
-
|
|
|
624
|
-
|
|
|
625
|
-
|
|
|
626
|
-
|
|
|
840
|
+
| Network | Chain ID | Tokens | Status |
|
|
841
|
+
|---------|----------|--------|--------|
|
|
842
|
+
| Ethereum | 1 | USDC, EURC, AUSD, PYUSD, GHO, crvUSD | Enabled |
|
|
843
|
+
| Base | 8453 | USDC, EURC, GHO | Enabled |
|
|
844
|
+
| Avalanche | 43114 | USDC, EURC, AUSD | Enabled |
|
|
845
|
+
| Arbitrum | 42161 | USDC, AUSD, GHO, crvUSD | Enabled |
|
|
846
|
+
| Polygon | 137 | USDC, AUSD | Enabled |
|
|
847
|
+
| Monad | 143 | USDC, AUSD | Enabled |
|
|
848
|
+
| Optimism | 10 | USDC | Enabled |
|
|
849
|
+
| Celo | 42220 | USDC | Enabled |
|
|
850
|
+
| HyperEVM | 999 | USDC | Enabled |
|
|
851
|
+
| Unichain | 130 | USDC | Enabled |
|
|
627
852
|
|
|
628
853
|
### SVM Networks (2)
|
|
629
854
|
|
|
@@ -667,8 +892,8 @@ interface X402ClientConfig {
|
|
|
667
892
|
| `connect(chainName?)` | Connect wallet to specified chain |
|
|
668
893
|
| `disconnect()` | Disconnect current wallet |
|
|
669
894
|
| `switchChain(chainName)` | Switch to different EVM chain |
|
|
670
|
-
| `createPayment(paymentInfo)` | Create payment authorization |
|
|
671
|
-
| `getBalance()` | Get
|
|
895
|
+
| `createPayment(paymentInfo)` | Create payment authorization (supports `tokenType` in paymentInfo) |
|
|
896
|
+
| `getBalance(tokenType?)` | Get token balance on current chain (defaults to USDC) |
|
|
672
897
|
| `getState()` | Get current wallet state |
|
|
673
898
|
| `isConnected()` | Check if wallet is connected |
|
|
674
899
|
| `on(event, handler)` | Subscribe to events |
|
|
@@ -686,9 +911,23 @@ import {
|
|
|
686
911
|
isSVMChain,
|
|
687
912
|
getExplorerTxUrl,
|
|
688
913
|
getExplorerAddressUrl,
|
|
914
|
+
// Multi-token utilities
|
|
915
|
+
getTokenConfig,
|
|
916
|
+
getSupportedTokens,
|
|
917
|
+
isTokenSupported,
|
|
918
|
+
getChainsByToken,
|
|
689
919
|
} from 'uvd-x402-sdk';
|
|
690
920
|
```
|
|
691
921
|
|
|
922
|
+
### Token Utilities
|
|
923
|
+
|
|
924
|
+
| Function | Description |
|
|
925
|
+
|----------|-------------|
|
|
926
|
+
| `getTokenConfig(chain, tokenType)` | Get token config (address, decimals, name, version) |
|
|
927
|
+
| `getSupportedTokens(chain)` | Get array of supported token types for a chain |
|
|
928
|
+
| `isTokenSupported(chain, tokenType)` | Check if token is available on chain |
|
|
929
|
+
| `getChainsByToken(tokenType)` | Get all chains that support a specific token |
|
|
930
|
+
|
|
692
931
|
### x402 Utilities
|
|
693
932
|
|
|
694
933
|
```typescript
|
|
@@ -705,6 +944,34 @@ import {
|
|
|
705
944
|
} from 'uvd-x402-sdk';
|
|
706
945
|
```
|
|
707
946
|
|
|
947
|
+
### Wagmi Adapter
|
|
948
|
+
|
|
949
|
+
```typescript
|
|
950
|
+
import {
|
|
951
|
+
createPaymentFromWalletClient,
|
|
952
|
+
createPaymentWithResult,
|
|
953
|
+
useX402Wagmi,
|
|
954
|
+
} from 'uvd-x402-sdk/wagmi';
|
|
955
|
+
```
|
|
956
|
+
|
|
957
|
+
| Function | Description |
|
|
958
|
+
|----------|-------------|
|
|
959
|
+
| `createPaymentFromWalletClient(walletClient, options)` | Create payment header using wagmi's WalletClient |
|
|
960
|
+
| `createPaymentWithResult(walletClient, options)` | Same as above but returns full PaymentResult |
|
|
961
|
+
| `useX402Wagmi(walletClient)` | Helper hook returning `{ createPayment, isReady }` |
|
|
962
|
+
|
|
963
|
+
#### Options
|
|
964
|
+
|
|
965
|
+
```typescript
|
|
966
|
+
interface WagmiPaymentOptions {
|
|
967
|
+
recipient: string; // Recipient address
|
|
968
|
+
amount: string; // Amount in token (e.g., "10.00")
|
|
969
|
+
chainName?: string; // Chain name (default: 'base')
|
|
970
|
+
tokenType?: TokenType; // Token type (default: 'usdc')
|
|
971
|
+
validitySeconds?: number; // Signature validity window (default: 300)
|
|
972
|
+
}
|
|
973
|
+
```
|
|
974
|
+
|
|
708
975
|
---
|
|
709
976
|
|
|
710
977
|
## Error Handling
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { f as PaymentResult } from '../index-BHwtdJrt.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* uvd-x402-sdk - Wagmi/Viem Adapter
|
|
5
|
+
*
|
|
6
|
+
* Provides integration with wagmi/viem for projects using RainbowKit,
|
|
7
|
+
* ConnectKit, or other wagmi-based wallet connection libraries.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { useWalletClient } from 'wagmi';
|
|
12
|
+
* import { createPaymentFromWalletClient } from 'uvd-x402-sdk/wagmi';
|
|
13
|
+
*
|
|
14
|
+
* function PayButton() {
|
|
15
|
+
* const { data: walletClient } = useWalletClient();
|
|
16
|
+
*
|
|
17
|
+
* const handlePay = async () => {
|
|
18
|
+
* const paymentHeader = await createPaymentFromWalletClient(walletClient, {
|
|
19
|
+
* recipient: '0x...',
|
|
20
|
+
* amount: '1.00',
|
|
21
|
+
* chainName: 'base',
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Use in your API request
|
|
25
|
+
* await fetch('/api/paid-endpoint', {
|
|
26
|
+
* headers: { 'X-PAYMENT': paymentHeader }
|
|
27
|
+
* });
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* return <button onClick={handlePay}>Pay $1.00</button>;
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Viem WalletClient interface (minimal type to avoid viem dependency)
|
|
37
|
+
*/
|
|
38
|
+
interface WalletClient {
|
|
39
|
+
account: {
|
|
40
|
+
address: `0x${string}`;
|
|
41
|
+
};
|
|
42
|
+
signTypedData: (args: {
|
|
43
|
+
domain: {
|
|
44
|
+
name: string;
|
|
45
|
+
version: string;
|
|
46
|
+
chainId: number;
|
|
47
|
+
verifyingContract: `0x${string}`;
|
|
48
|
+
};
|
|
49
|
+
types: Record<string, Array<{
|
|
50
|
+
name: string;
|
|
51
|
+
type: string;
|
|
52
|
+
}>>;
|
|
53
|
+
primaryType: string;
|
|
54
|
+
message: Record<string, unknown>;
|
|
55
|
+
}) => Promise<`0x${string}`>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Payment options for wagmi adapter
|
|
59
|
+
*/
|
|
60
|
+
interface WagmiPaymentOptions {
|
|
61
|
+
/** Recipient address */
|
|
62
|
+
recipient: string;
|
|
63
|
+
/** Amount in USDC (e.g., "1.00", "10.50") */
|
|
64
|
+
amount: string;
|
|
65
|
+
/** Chain name (default: 'base') */
|
|
66
|
+
chainName?: string;
|
|
67
|
+
/** Validity window in seconds (default: 300 = 5 minutes) */
|
|
68
|
+
validitySeconds?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create an x402 payment header using a wagmi/viem WalletClient
|
|
72
|
+
*
|
|
73
|
+
* This function allows you to use the x402 SDK with wagmi-based wallet
|
|
74
|
+
* connections (RainbowKit, ConnectKit, etc.) instead of the built-in
|
|
75
|
+
* wallet connection.
|
|
76
|
+
*
|
|
77
|
+
* @param walletClient - The WalletClient from wagmi's useWalletClient hook
|
|
78
|
+
* @param options - Payment options (recipient, amount, chainName)
|
|
79
|
+
* @returns Base64-encoded payment header ready for X-PAYMENT HTTP header
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```tsx
|
|
83
|
+
* import { useWalletClient } from 'wagmi';
|
|
84
|
+
* import { createPaymentFromWalletClient } from 'uvd-x402-sdk/wagmi';
|
|
85
|
+
*
|
|
86
|
+
* const { data: walletClient } = useWalletClient();
|
|
87
|
+
*
|
|
88
|
+
* const paymentHeader = await createPaymentFromWalletClient(walletClient, {
|
|
89
|
+
* recipient: '0xRecipientAddress',
|
|
90
|
+
* amount: '5.00',
|
|
91
|
+
* chainName: 'base',
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare function createPaymentFromWalletClient(walletClient: WalletClient | undefined | null, options: WagmiPaymentOptions): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Create payment with full result object (includes metadata)
|
|
98
|
+
*
|
|
99
|
+
* Same as createPaymentFromWalletClient but returns a PaymentResult
|
|
100
|
+
* object with additional metadata.
|
|
101
|
+
*
|
|
102
|
+
* @param walletClient - The WalletClient from wagmi
|
|
103
|
+
* @param options - Payment options
|
|
104
|
+
* @returns PaymentResult with paymentHeader and metadata
|
|
105
|
+
*/
|
|
106
|
+
declare function createPaymentWithResult(walletClient: WalletClient | undefined | null, options: WagmiPaymentOptions): Promise<PaymentResult>;
|
|
107
|
+
/**
|
|
108
|
+
* React hook helper for wagmi integration
|
|
109
|
+
*
|
|
110
|
+
* Returns a function that creates payments using the connected wallet.
|
|
111
|
+
* This is a simple wrapper - for more control, use createPaymentFromWalletClient directly.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```tsx
|
|
115
|
+
* import { useWalletClient } from 'wagmi';
|
|
116
|
+
* import { useX402Wagmi } from 'uvd-x402-sdk/wagmi';
|
|
117
|
+
*
|
|
118
|
+
* function PayButton() {
|
|
119
|
+
* const { data: walletClient } = useWalletClient();
|
|
120
|
+
* const { createPayment, isReady } = useX402Wagmi(walletClient);
|
|
121
|
+
*
|
|
122
|
+
* return (
|
|
123
|
+
* <button
|
|
124
|
+
* disabled={!isReady}
|
|
125
|
+
* onClick={() => createPayment({ recipient: '0x...', amount: '1.00' })}
|
|
126
|
+
* >
|
|
127
|
+
* Pay
|
|
128
|
+
* </button>
|
|
129
|
+
* );
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
declare function useX402Wagmi(walletClient: WalletClient | undefined | null): {
|
|
134
|
+
isReady: boolean;
|
|
135
|
+
createPayment: (options: WagmiPaymentOptions) => Promise<string>;
|
|
136
|
+
createPaymentFull: (options: WagmiPaymentOptions) => Promise<PaymentResult>;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export { type WagmiPaymentOptions, type WalletClient, createPaymentFromWalletClient, createPaymentWithResult, useX402Wagmi };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { f as PaymentResult } from '../index-BHwtdJrt.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* uvd-x402-sdk - Wagmi/Viem Adapter
|
|
5
|
+
*
|
|
6
|
+
* Provides integration with wagmi/viem for projects using RainbowKit,
|
|
7
|
+
* ConnectKit, or other wagmi-based wallet connection libraries.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { useWalletClient } from 'wagmi';
|
|
12
|
+
* import { createPaymentFromWalletClient } from 'uvd-x402-sdk/wagmi';
|
|
13
|
+
*
|
|
14
|
+
* function PayButton() {
|
|
15
|
+
* const { data: walletClient } = useWalletClient();
|
|
16
|
+
*
|
|
17
|
+
* const handlePay = async () => {
|
|
18
|
+
* const paymentHeader = await createPaymentFromWalletClient(walletClient, {
|
|
19
|
+
* recipient: '0x...',
|
|
20
|
+
* amount: '1.00',
|
|
21
|
+
* chainName: 'base',
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Use in your API request
|
|
25
|
+
* await fetch('/api/paid-endpoint', {
|
|
26
|
+
* headers: { 'X-PAYMENT': paymentHeader }
|
|
27
|
+
* });
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* return <button onClick={handlePay}>Pay $1.00</button>;
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Viem WalletClient interface (minimal type to avoid viem dependency)
|
|
37
|
+
*/
|
|
38
|
+
interface WalletClient {
|
|
39
|
+
account: {
|
|
40
|
+
address: `0x${string}`;
|
|
41
|
+
};
|
|
42
|
+
signTypedData: (args: {
|
|
43
|
+
domain: {
|
|
44
|
+
name: string;
|
|
45
|
+
version: string;
|
|
46
|
+
chainId: number;
|
|
47
|
+
verifyingContract: `0x${string}`;
|
|
48
|
+
};
|
|
49
|
+
types: Record<string, Array<{
|
|
50
|
+
name: string;
|
|
51
|
+
type: string;
|
|
52
|
+
}>>;
|
|
53
|
+
primaryType: string;
|
|
54
|
+
message: Record<string, unknown>;
|
|
55
|
+
}) => Promise<`0x${string}`>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Payment options for wagmi adapter
|
|
59
|
+
*/
|
|
60
|
+
interface WagmiPaymentOptions {
|
|
61
|
+
/** Recipient address */
|
|
62
|
+
recipient: string;
|
|
63
|
+
/** Amount in USDC (e.g., "1.00", "10.50") */
|
|
64
|
+
amount: string;
|
|
65
|
+
/** Chain name (default: 'base') */
|
|
66
|
+
chainName?: string;
|
|
67
|
+
/** Validity window in seconds (default: 300 = 5 minutes) */
|
|
68
|
+
validitySeconds?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create an x402 payment header using a wagmi/viem WalletClient
|
|
72
|
+
*
|
|
73
|
+
* This function allows you to use the x402 SDK with wagmi-based wallet
|
|
74
|
+
* connections (RainbowKit, ConnectKit, etc.) instead of the built-in
|
|
75
|
+
* wallet connection.
|
|
76
|
+
*
|
|
77
|
+
* @param walletClient - The WalletClient from wagmi's useWalletClient hook
|
|
78
|
+
* @param options - Payment options (recipient, amount, chainName)
|
|
79
|
+
* @returns Base64-encoded payment header ready for X-PAYMENT HTTP header
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```tsx
|
|
83
|
+
* import { useWalletClient } from 'wagmi';
|
|
84
|
+
* import { createPaymentFromWalletClient } from 'uvd-x402-sdk/wagmi';
|
|
85
|
+
*
|
|
86
|
+
* const { data: walletClient } = useWalletClient();
|
|
87
|
+
*
|
|
88
|
+
* const paymentHeader = await createPaymentFromWalletClient(walletClient, {
|
|
89
|
+
* recipient: '0xRecipientAddress',
|
|
90
|
+
* amount: '5.00',
|
|
91
|
+
* chainName: 'base',
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare function createPaymentFromWalletClient(walletClient: WalletClient | undefined | null, options: WagmiPaymentOptions): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Create payment with full result object (includes metadata)
|
|
98
|
+
*
|
|
99
|
+
* Same as createPaymentFromWalletClient but returns a PaymentResult
|
|
100
|
+
* object with additional metadata.
|
|
101
|
+
*
|
|
102
|
+
* @param walletClient - The WalletClient from wagmi
|
|
103
|
+
* @param options - Payment options
|
|
104
|
+
* @returns PaymentResult with paymentHeader and metadata
|
|
105
|
+
*/
|
|
106
|
+
declare function createPaymentWithResult(walletClient: WalletClient | undefined | null, options: WagmiPaymentOptions): Promise<PaymentResult>;
|
|
107
|
+
/**
|
|
108
|
+
* React hook helper for wagmi integration
|
|
109
|
+
*
|
|
110
|
+
* Returns a function that creates payments using the connected wallet.
|
|
111
|
+
* This is a simple wrapper - for more control, use createPaymentFromWalletClient directly.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```tsx
|
|
115
|
+
* import { useWalletClient } from 'wagmi';
|
|
116
|
+
* import { useX402Wagmi } from 'uvd-x402-sdk/wagmi';
|
|
117
|
+
*
|
|
118
|
+
* function PayButton() {
|
|
119
|
+
* const { data: walletClient } = useWalletClient();
|
|
120
|
+
* const { createPayment, isReady } = useX402Wagmi(walletClient);
|
|
121
|
+
*
|
|
122
|
+
* return (
|
|
123
|
+
* <button
|
|
124
|
+
* disabled={!isReady}
|
|
125
|
+
* onClick={() => createPayment({ recipient: '0x...', amount: '1.00' })}
|
|
126
|
+
* >
|
|
127
|
+
* Pay
|
|
128
|
+
* </button>
|
|
129
|
+
* );
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
declare function useX402Wagmi(walletClient: WalletClient | undefined | null): {
|
|
134
|
+
isReady: boolean;
|
|
135
|
+
createPayment: (options: WagmiPaymentOptions) => Promise<string>;
|
|
136
|
+
createPaymentFull: (options: WagmiPaymentOptions) => Promise<PaymentResult>;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export { type WagmiPaymentOptions, type WalletClient, createPaymentFromWalletClient, createPaymentWithResult, useX402Wagmi };
|