building-with-base-account
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBuilding with Base Account
基于Base Account开发
Base Account is an ERC-4337 smart wallet providing universal sign-on, one-tap USDC payments, and multi-chain support (Base, Arbitrum, Optimism, Zora, Polygon, BNB, Avalanche, Lordchain, Ethereum Mainnet).
Base Account是一款ERC-4337标准的智能钱包,提供通用登录、一键USDC支付以及多链支持(Base、Arbitrum、Optimism、Zora、Polygon、BNB、Avalanche、Lordchain、以太坊主网)。
Quick Start
快速开始
bash
npm install @base-org/account @base-org/account-uitypescript
import { createBaseAccountSDK } from '@base-org/account';
const sdk = createBaseAccountSDK({
appName: 'My App',
appLogoUrl: 'https://example.com/logo.png',
appChainIds: [8453], // Base Mainnet
});
const provider = sdk.getProvider();bash
npm install @base-org/account @base-org/account-uitypescript
import { createBaseAccountSDK } from '@base-org/account';
const sdk = createBaseAccountSDK({
appName: 'My App',
appLogoUrl: 'https://example.com/logo.png',
appChainIds: [8453], // Base Mainnet
});
const provider = sdk.getProvider();Feature References
功能参考文档
Read the reference for the feature you're implementing:
| Feature | Reference | When to Read |
|---|---|---|
| Sign in with Base | references/authentication.md | Wallet auth, SIWE, backend verification, SignInWithBaseButton, Wagmi/Privy setup |
| Base Pay | references/payments.md | One-tap USDC payments, payerInfo, server-side verification, BasePayButton |
| Subscriptions | references/subscriptions.md | Recurring charges, spend permissions, CDP wallet setup, charge/revoke lifecycle |
| Sub Accounts | references/sub-accounts.md | App-specific embedded wallets, key generation, funding |
| Capabilities | references/capabilities.md | Batch transactions, gas sponsorship (paymasters), atomic execution, auxiliaryFunds, attribution |
| Prolinks | references/prolinks.md | Shareable payment links, QR codes, encoded transaction URLs |
| Troubleshooting | references/troubleshooting.md | Popup issues, gas usage, unsupported calls, migration, doc links |
请查阅你要实现的功能对应的参考文档:
| 功能 | 参考文档 | 适用场景 |
|---|---|---|
| Sign in with Base | references/authentication.md | 钱包认证、SIWE、后端验证、SignInWithBaseButton、Wagmi/Privy配置 |
| Base Pay | references/payments.md | 一键USDC支付、付款人信息、服务端验证、BasePayButton |
| 订阅服务 | references/subscriptions.md | 定期扣费、消费权限、CDP钱包配置、扣费/撤销生命周期 |
| 子账户 | references/sub-accounts.md | 应用专属嵌入式钱包、密钥生成、资金充值 |
| 扩展功能 | references/capabilities.md | 批量交易、Gas赞助(Paymasters)、原子执行、辅助资金、归因追踪 |
| Prolinks | references/prolinks.md | 可分享支付链接、二维码、编码交易URL |
| 问题排查 | references/troubleshooting.md | 弹窗问题、Gas消耗、不支持的调用、迁移、文档链接 |
Critical Requirements
关键要求
Security
安全
- Track transaction IDs to prevent replay attacks
- Verify sender matches authenticated user to prevent impersonation
- Use a proxy to protect Paymaster URLs from frontend exposure
- Paymaster providers must be ERC-7677-compliant
- Never expose CDP credentials client-side (subscription backend only)
- 追踪交易ID以防止重放攻击
- 验证发送方与已认证用户匹配以防止冒充
- 使用代理以避免Paymaster URL暴露在前端
- Paymaster服务提供商必须符合ERC-7677标准
- 切勿在客户端暴露CDP凭证(仅在订阅服务后端使用)
Popup Handling
弹窗处理
- Generate nonces before user clicks "Sign in" to avoid popup blockers
- Use
Cross-Origin-Opener-Policy: same-origin-allow-popups - breaks the Base Account popup
same-origin
- 在用户点击“登录”之前生成随机数,以避免被弹窗拦截器阻止
- 使用
Cross-Origin-Opener-Policy: same-origin-allow-popups - 会导致Base Account弹窗无法正常工作
same-origin
Base Pay
Base Pay
- Base Pay works independently from SIWB — no auth required for
pay() - param in
testnetmust matchgetPaymentStatus()callpay() - Never disable actions based on onchain balance alone — check capability
auxiliaryFunds
- Base Pay可独立于SIWB使用——调用无需认证
pay() - 中的
getPaymentStatus()参数必须与testnet调用时的参数一致pay() - 切勿仅依据链上余额禁用操作——请检查功能
auxiliaryFunds
Sub Accounts
子账户
- Call each session before use
wallet_addSubAccount - Ownership changes expected on new devices/browsers
- Only Coinbase Smart Wallet contracts supported for import
- 每次会话使用前调用
wallet_addSubAccount - 在新设备/浏览器上使用时,所有权会发生变化
- 仅支持导入Coinbase Smart Wallet合约
Smart Wallets
智能钱包
- ERC-6492 wrapper enables signature verification before wallet deployment
- Viem's /
verifyMessagehandle this automaticallyverifyTypedData
- ERC-6492包装器支持在钱包部署前进行签名验证
- Viem的/
verifyMessage会自动处理此操作verifyTypedData
For Edge Cases and Latest API Changes
边缘场景与最新API变更
- AI-optimized docs: docs.base.org/llms.txt
- Full reference: docs.base.org/base-account
- AI优化文档: docs.base.org/llms.txt
- 完整参考文档: docs.base.org/base-account