Files
dbis-thirdweb/packages/x402/README.md
2026-01-01 08:04:06 -08:00

44 lines
1.1 KiB
Markdown

# @dbis-thirdweb/x402
x402 payment primitives and pay-to-access flows for Chain 138.
## Usage
### Pay-to-Access Flow
```typescript
import { PayToAccessFlow, InMemoryReplayProtectionStore } from '@dbis-thirdweb/x402';
import { ThirdwebSDK } from '@thirdweb-dev/sdk';
import { chain138 } from '@dbis-thirdweb/chain';
// Server-side: Create request
const sdk = new ThirdwebSDK(chain138);
const provider = sdk.getProvider();
const replayStore = new InMemoryReplayProtectionStore();
const flow = new PayToAccessFlow(provider, replayStore);
const request = await flow.createRequest({
amount: ethers.utils.parseEther('0.01'),
recipient: '0x...',
expiresInSeconds: 3600,
});
const challenge = flow.generateChallenge(request);
// Client-side: Fulfill payment
const signer = await wallet.getSigner();
const receipt = await flow.fulfillPayment(challenge, signer);
// Server-side: Verify payment
const isValid = await flow.verifyPayment(receipt, request);
```
## Features
- Payment request creation and validation
- Replay protection via request ID tracking
- Receipt verification on-chain
- Pay-to-access flow implementation
- Expiration handling