TypeScript SDK for the x402 Universal Payments Protocol β enabling seamless blockchain payments with Smart Accounts.
- π Smart Account Management β Create and manage EIP-4337 compatible accounts
- πΈ x402 Payments β EIP-3009 transfer authorizations with typed signatures
- βοΈ React Hooks β First-class React integration with TanStack Query
- π Multi-Chain β TAU, Base, Base Sepolia, and Ethereum Mainnet support
- π¦ Dual Build β ESM and CommonJS compatible
# Using pnpm (recommended)
pnpm add @gatewayfm/ups-sdk
# For React projects
pnpm add @gatewayfm/ups-sdk @gatewayfm/ups-reactimport { UPSClient } from '@gatewayfm/ups-sdk';
const client = new UPSClient({
baseUrl: 'https://api.ups.example.com',
network: 'eip155:737998412', // TAU Testnet
});
// Connect wallet (EIP-1193 provider)
await client.connect(window.ethereum);
// Authenticate with the UPS backend
await client.authenticate();
// Create a Smart Account
const { account, txHash } = await client.account.create({
ownerAddress: client.wallet.getAddress()!,
salt: '0x' + crypto.randomUUID().replace(/-/g, '').padEnd(64, '0'),
});
console.log('Account created:', account.walletAddress);import { UPSProvider, useWallet, useAccount, usePayment } from '@gatewayfm/ups-react';
function App() {
return (
<UPSProvider config={{ baseUrl: '...', network: 'eip155:737998412' }}>
<PaymentFlow />
</UPSProvider>
);
}
function PaymentFlow() {
const { connect, isConnected, address } = useWallet();
const { createAccount } = useAccount();
const { pay, isPaying } = usePayment();
return (
<div>
{!isConnected ? (
<button onClick={() => connect(window.ethereum)}>
Connect Wallet
</button>
) : (
<p>Connected: {address}</p>
)}
</div>
);
}| Package | Description | Docs |
|---|---|---|
@gatewayfm/ups-sdk |
Core SDK β wallet, account, and payment modules | README |
@gatewayfm/ups-react |
React hooks and context provider | README |
@gatewayfm/test-utils |
Testing utilities and mocks | β |
See the examples/ directory:
- Basic Node.js β Standalone TypeScript example
- Basic Node.js β Standalone TypeScript example
- React + Vite β Full React application
- React Invoice β Invoice Management application
- React Escrow β Escrow Payment application
# Run the basic example
cd examples/basic
pnpm install
pnpm startclient.wallet β Wallet connection and signing
await client.connect(provider); // Connect EIP-1193 wallet
await client.wallet.signMessage(msg); // Sign personal message
await client.wallet.signTypedData(data); // Sign EIP-712 typed data
client.wallet.getAddress(); // Get connected addressclient.account β Smart Account management
await client.account.list(); // List user's accounts
await client.account.create(params); // Create new account
await client.account.predictAddress(p); // Predict future addressclient.payment β x402 payment flow
await client.payment.pay({ requirements, from }); // Full payment flow
await client.payment.verify(signed, requirements); // Verify before settling
await client.payment.settle(signed, requirements); // Settle on-chain
await client.payment.payInvoice(invoice, { amount, asset, network });client.invoice β Invoice operations
await client.invoice.create({ amount, due_date, ... });
await client.invoice.list({ merchant: '0x...' });| Hook | Purpose |
|---|---|
useWallet() |
Wallet connection, address, chain ID |
useAuth() |
Authentication state and actions |
useAccount() |
Account CRUD with query caching |
useAccount() |
Account CRUD with query caching |
usePayment() |
Payment execution with loading states |
useInvoice() |
Invoice management hooks |
useUPSClient() |
Direct SDK client access |
- Node.js >= 18
- pnpm >= 9
git clone https://github.com/gateway-fm/ups-typescript.git
cd ups-typescript
pnpm install
pnpm build| Command | Description |
|---|---|
pnpm build |
Build all packages |
pnpm test |
Run unit tests |
pnpm test:coverage |
Run tests with coverage |
pnpm lint |
Lint all packages |
pnpm typecheck |
TypeScript type checking |
pnpm dev |
Watch mode |
Create a .env file:
API_BASE_URL=https://api.ups.example.com
BLOCKCHAIN_RPC_URL=https://sepolia.base.org
BLOCKCHAIN_CHAIN_ID=84532See SECRETS.md for handling sensitive keys.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing) - Open a Pull Request
MIT Β© Gateway.fm
Built with β€οΈ for the x402 ecosystem