building-with-base-account

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Building 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-ui
typescript
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-ui
typescript
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:
FeatureReferenceWhen to Read
Sign in with Basereferences/authentication.mdWallet auth, SIWE, backend verification, SignInWithBaseButton, Wagmi/Privy setup
Base Payreferences/payments.mdOne-tap USDC payments, payerInfo, server-side verification, BasePayButton
Subscriptionsreferences/subscriptions.mdRecurring charges, spend permissions, CDP wallet setup, charge/revoke lifecycle
Sub Accountsreferences/sub-accounts.mdApp-specific embedded wallets, key generation, funding
Capabilitiesreferences/capabilities.mdBatch transactions, gas sponsorship (paymasters), atomic execution, auxiliaryFunds, attribution
Prolinksreferences/prolinks.mdShareable payment links, QR codes, encoded transaction URLs
Troubleshootingreferences/troubleshooting.mdPopup issues, gas usage, unsupported calls, migration, doc links
请查阅你要实现的功能对应的参考文档:
功能参考文档适用场景
Sign in with Basereferences/authentication.md钱包认证、SIWE、后端验证、SignInWithBaseButton、Wagmi/Privy配置
Base Payreferences/payments.md一键USDC支付、付款人信息、服务端验证、BasePayButton
订阅服务references/subscriptions.md定期扣费、消费权限、CDP钱包配置、扣费/撤销生命周期
子账户references/sub-accounts.md应用专属嵌入式钱包、密钥生成、资金充值
扩展功能references/capabilities.md批量交易、Gas赞助(Paymasters)、原子执行、辅助资金、归因追踪
Prolinksreferences/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
  • same-origin
    breaks the Base Account popup
  • 在用户点击“登录”之前生成随机数,以避免被弹窗拦截器阻止
  • 使用
    Cross-Origin-Opener-Policy: same-origin-allow-popups
  • same-origin
    会导致Base Account弹窗无法正常工作

Base Pay

Base Pay

  • Base Pay works independently from SIWB — no auth required for
    pay()
  • testnet
    param in
    getPaymentStatus()
    must match
    pay()
    call
  • Never disable actions based on onchain balance alone — check
    auxiliaryFunds
    capability
  • Base Pay可独立于SIWB使用——调用
    pay()
    无需认证
  • getPaymentStatus()
    中的
    testnet
    参数必须与
    pay()
    调用时的参数一致
  • 切勿仅依据链上余额禁用操作——请检查
    auxiliaryFunds
    功能

Sub Accounts

子账户

  • Call
    wallet_addSubAccount
    each session before use
  • 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
    verifyMessage
    /
    verifyTypedData
    handle this automatically
  • ERC-6492包装器支持在钱包部署前进行签名验证
  • Viem的
    verifyMessage
    /
    verifyTypedData
    会自动处理此操作

For Edge Cases and Latest API Changes

边缘场景与最新API变更