集成

privy-integration

试用

在 React 与 Node 应用中接入 Privy 登录、嵌入式钱包及 x402/MPP 机器支付协议

它能做什么

提供 Privy 官方 SDK 的集成指引,覆盖 @privy-io/react-auth(含 /solana 与 /smart-wallets 即 ERC-4337 子模块)、@privy-io/node 服务端 SDK 与 @privy-io/wagmi 连接器。内容包括邮箱/手机/社交/Passkey/钱包登录、白标登录 UI、服务端 token 校验(privy.utils().auth())、Solana 钱包 hooks、自 v3.7.0 起内置于 React SDK 的 x402 支付,以及在 Tempo 链结算 PathUSD/USDC 等稳定币的 MPP 机器支付(支持会话高频扣款)。另含策略受限的代理钱包,两种控制模式:完全由代理自主控制、由用户持有但代理签名的双层模式,并附带 Agent Auth Protocol 与 MCP 授权的对接参考。

什么时候用它

  • 在 React/Next.js 项目中接入 Privy 登录与嵌入式钱包
  • 将 wagmi/viem 接入已有的 Privy 钱包
  • 为 API 接入 x402 或 MPP/Tempo 机器支付
  • 为自主代理构建带策略约束的服务端钱包

技能文档

Privy Integration

Privy provides authentication and wallet infrastructure for apps built on crypto rails. Embed self-custodial wallets, authenticate users via email/SMS/socials/passkeys/wallets, and transact on EVM and Solana chains. Also supports agent payment protocols (x402, MPP) and autonomous agentic wallets.

Key packages:

  • @privy-io/react-auth - React SDK (auth + wallets + x402)
  • @privy-io/react-auth/solana - Solana wallet hooks
  • @privy-io/react-auth/smart-wallets - Smart wallets (ERC-4337)
  • @privy-io/wagmi - wagmi v2 connector
  • @privy-io/node - Server-side SDK (replaces deprecated @privy-io/server-auth)
  • mppx - MPP client/server SDK (settles on Tempo)

Docs: Privy ships an official agent skill - npx skills add https://docs.privy.io (or fetch https://docs.privy.io/skill.md). The machine-readable doc index is https://docs.privy.io/llms-full.txt (plus sitemap.xml); llms.txt now only points to the skill installer. Privy restructures docs often - do not guess URLs, they 404.

Workflow Decision Tree

Setting up Privy auth in a React app? -> Quick Start below, then references/react-sdk.md Adding wagmi/viem to a Privy app? -> Wagmi Integration below, then references/react-sdk.md Working server-side (Node.js)? -> Server-Side section below, then references/server-sdk.md Adding x402 or MPP payments? -> x402/MPP sections below, then references/agent-payments.md Building agentic wallets or agent auth? -> Agentic Wallets below, then references/agent-auth.md Solana-specific integration? -> references/solana.md Wallet management (smart wallets, policies, funding)? -> references/wallets.md Wallet actions (DeFi earn, swap, cross-chain transfer/bridge)? -> Wallet Actions in references/wallets.md

Quick Start (React + Next.js)

1. Install

npm i @privy-io/react-auth

2. Wrap app with PrivyProvider

'use client';
import {PrivyProvider} from '@privy-io/react-auth';

export default function Providers({children}: {children: React.ReactNode}) {
  return (
    
      {children}
    
  );
}

3. Check readiness before using hooks

import {usePrivy} from '@privy-io/react-auth';

function App() {
  const {ready, authenticated, user} = usePrivy();
  if (!ready) return Loading...;
  // Safe to use Privy hooks now
}

4. Login (email OTP example)

import {useLoginWithEmail} from '@privy-io/react-auth';

function LoginForm() {
  const {sendCode, loginWithCode} = useLoginWithEmail();
  // sendCode({email}) then loginWithCode({code})
}

5. Send a transaction (EVM)

import {useSendTransaction} from '@privy-io/react-auth';

function SendButton() {
  const {sendTransaction} = useSendTransaction();
  return (
     sendTransaction({to: '0x...', value: 100000})}>
      Send
    
  );
}

PrivyProvider Config

config={{
  // Auth methods enabled for login
  loginMethods: ['email', 'sms', 'wallet', 'google', 'apple', 'twitter',
                 'github', 'discord', 'farcaster', 'telegram', 'passkey'],

  // Embedded wallet creation
  embeddedWallets: {
    ethereum: {createOnLogin: 'users-without-wallets'}, // or 'all-users' | 'off'
    solana: {createOnLogin: 'users-without-wallets'}
  },

  // UI appearance
  appearance: {
    showWalletLoginFirst: false,
    walletChainType: 'ethereum-and-solana', // or 'ethereum-only' | 'solana-only'
    theme: 'light', // or 'dark'
    accentColor: '#6A6FF5',
    logo: 'https://your-logo.png'
  },

  // External wallet connectors (Solana)
  externalWallets: {
    solana: {connectors: toSolanaWalletConnectors()}
  },

  // Solana RPC config (required for embedded wallet UIs)
  solana: {
    rpcs: {
      'solana:mainnet': {
        rpc: createSolanaRpc('https://api.mainnet-beta.solana.com'),
        rpcSubscriptions: createSolanaRpcSubscriptions('wss://api.mainnet-beta.solana.com')
      }
    }
  }
}}

Wagmi Integration

Import createConfig and WagmiProvider from @privy-io/wagmi (NOT from wagmi).

npm i @privy-io/react-auth @privy-io/wagmi wagmi @tanstack/react-query
import {PrivyProvider} from '@privy-io/react-auth';
import {WagmiProvider, createConfig} from '@privy-io/wagmi';
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
import {mainnet, base} from 'viem/chains';
import {http} from 'wagmi';

const queryClient = new QueryClient();
const wagmiConfig = createConfig({
  chains: [mainnet, base],
  transports: {[mainnet.id]: http(), [base.id]: http()}
});

// Nesting order: PrivyProvider > QueryClientProvider > WagmiProvider
export default function Providers({children}: {children: React.ReactNode}) {
  return (
    
      
        {children}
      
    
  );
}

Use wagmi hooks (useAccount, useSendTransaction, etc.) for read/write actions. Use Privy hooks for wallet connection/creation.

Server-Side Token Verification

npm i @privy-io/node
import {PrivyClient} from '@privy-io/node';

const privy = new PrivyClient({
  appId: process.env.PRIVY_APP_ID!,
  appSecret: process.env.PRIVY_APP_SECRET!
});

// Verify access token from Authorization header
// (top-level privy.verifyAuthToken is deprecated - use utils().auth())
const {userId} = await privy.utils().auth().verifyAccessToken(accessToken);

Whitelabel Authentication

All auth flows can be fully whitelabeled with custom UI. Key hooks:

HookAuth method
useLoginWithEmailEmail OTP (sendCode, loginWithCode)
useLoginWithSmsSMS OTP
useLoginWithOAuthSocial logins (initOAuth({provider: 'google'}))
useLoginWithPasskeyPasskeys
useSignupWithPasskeyPasskey signup
useLoginWithTelegramTelegram
useLoginGeneral login with callbacks

Footgun: whitelabel flows (useLoginWithEmail, etc.) call Privy directly from the app domain, so they silently fail if that domain is not in the Dashboard's Allowed Origins/Domains - the hosted modal (usePrivy().login()) still works, masking the issue. Add every local dev port (e.g. localhost:5173) too. useLoginWithEmail's onError returns a rich object, not {message} - log the whole thing to see the real rejection.

x402 Payments (Quick Start)

Built into @privy-io/react-auth since v3.7.0. Handles HTTP 402 payment flows automatically using USDC.

import {useX402Fetch, useWallets} from '@privy-io/react-auth';

function PaidContent() {
  const {wallets} = useWallets();
  const {wrapFetchWithPayment} = useX402Fetch();

  const fetchContent = async () => {
    const fetchWithPayment = wrapFetchWithPayment({
      walletAddress: wallets[0]?.address,
      fetch,
      maxValue: BigInt(1000000) // Max 1 USDC
    });
    const res = await fetchWithPayment('https://api.example.com/premium');
    return res.json();
  };
}

Server-side (Node.js):

import {createX402Client} from '@privy-io/node/x402';
import {wrapFetchWithPayment} from '@x402/fetch';

const x402client = createX402Client(privy, {walletId: wallet.id, address: wallet.address});
const fetchWithPayment = wrapFetchWithPayment(fetch, x402client);
const response = await fetchWithPayment('https://api.example.com/premium');

MPP Payments (Quick Start)

MPP (Machine Payments Protocol) settles on Tempo using stablecoins (PathUSD, USDC, or others). Supports sessions for high-frequency payments.

import {Mppx, tempo} from 'mppx/client';

// Create Privy-backed viem account (see references/agent-payments.md for full pattern)
const account = createPrivyAccount(wallet.id, wallet.address);

const mppx = Mppx.create({polyfill: false, methods: [tempo({account})]});
const response = await mppx.fetch('https://api.example.com/weather');

Agentic Wallets (Quick Start)

Server-controlled wallets with policy-based constraints for autonomous agents.

// Create agent wallet
const wallet = await privy.wallets().create({chain_type: 'ethereum'});

// Execute transactions - validated against attached policies
const {hash} = await privy.wallets().ethereum().sendTransaction(wallet.id, {
  caip2: 'eip155:8453',
  params: {transaction: {to: '0x...', value: '0x1', chain_id: 8453}}
});

Two control models: agent-controlled (fully autonomous, developer-owned) and user-owned with agent signers (user retains revocation authority). See references/agent-auth.md for policy examples and setup.

Reference Docs

Read the appropriate reference file for detailed integration guides:

  • references/react-sdk.md - All React hooks, PrivyProvider config, wagmi/viem setup, appearance config, whitelabel patterns, wallet UI components
  • references/server-sdk.md - Node.js SDK (@privy-io/node), token types and verification, user management API, REST API, webhooks
  • references/wallets.md - Embedded wallets (EVM + Solana), smart wallets (ERC-4337), gas sponsorship, external connectors, policies and controls, funding, wallet export
  • references/solana.md - Solana-specific setup, connectors, @solana/kit and @solana/web3.js integration, transaction signing, gas sponsorship via fee payer
  • references/agent-payments.md - x402 protocol (React + Node.js), MPP with mppx SDK (client + server), Tempo blockchain (PathUSD, TIP-20), sessions, facilitators, x402 vs MPP comparison
  • references/agent-auth.md - Agentic wallets (policies, authorization keys, OpenClaw), Agent Auth Protocol (per-agent identity, capabilities), MCP authorization, Better Auth bridge

Key Documentation URLs

TopicURL
Full docs index (LLM-friendly)https://docs.privy.io/llms-full.txt
React setuphttps://docs.privy.io/basics/react/setup
React quickstarthttps://docs.privy.io/basics/react/quickstart
Auth overviewhttps://docs.privy.io/authentication/overview
Whitelabel authhttps://docs.privy.io/authentication/user-authentication/whitelabel
Tokens (access/refresh/identity)https://docs.privy.io/authentication/user-authentication/tokens
Wallets overviewhttps://docs.privy.io/wallets/overview
Wagmi integrationhttps://docs.privy.io/wallets/connectors/ethereum/integrations/wagmi
Viem integrationhttps://docs.privy.io/wallets/connectors/ethereum/integrations/viem
Smart walletshttps://docs.privy.io/wallets/using-wallets/evm-smart-wallets/overview
Smart wallets SDK confighttps://docs.privy.io/wallets/using-wallets/evm-smart-wallets/setup/configuring-sdk
Gas sponsorshiphttps://docs.privy.io/wallets/gas-and-asset-management/gas/overview
Gas on Ethereumhttps://docs.privy.io/wallets/gas-and-asset-management/gas/ethereum
Gas on Solanahttps://docs.privy.io/wallets/gas-and-asset-management/gas/solana
Node.js SDK quickstarthttps://docs.privy.io/basics/nodeJS/quickstart
Solana recipehttps://docs.privy.io/recipes/solana/getting-started-with-privy-and-solana
Connectors overviewhttps://docs.privy.io/wallets/connectors/overview
Custom auth provider (JWT)https://docs.privy.io/authentication/user-authentication/jwt-based-auth/overview
Webhookshttps://docs.privy.io/wallets/actions/webhooks
x402 integrationhttps://docs.privy.io/recipes/agent-integrations/x402
MPP integrationhttps://docs.privy.io/recipes/agent-integrations/mpp
Agentic walletshttps://docs.privy.io/recipes/agent-integrations/agentic-wallets
OpenClaw integrationhttps://docs.privy.io/recipes/agent-integrations/openclaw-agentic-wallets
Tempo chainhttps://docs.privy.io/recipes/tempo/send-transactions
Wallet policieshttps://docs.privy.io/controls/policies/overview
Wallet actions (earn/swap/transfer)https://docs.privy.io/wallets/actions/overview
Wallet signershttps://docs.privy.io/wallets/using-wallets/signers/overview
x402 protocolhttps://x402.org
MPP protocolhttps://mpp.dev
Agent Auth Protocolhttps://agentauthprotocol.com
MCP auth spechttps://modelcontextprotocol.io/specification/2025-11-25/basic/authorization

常见问题

涵盖哪些 SDK 与链?
同时覆盖 @privy-io/react-auth(含 /solana、/smart-wallets 子模块)与 @privy-io/node,以及 @privy-io/wagmi 连接器;EVM 与 Solana 两条链都支持,含 Solana RPC 配置与外部钱包连接器。
支持哪些机器支付协议?
x402(USDC,自 React SDK v3.7.0 起内置)用于 HTTP 402 付费接口;MPP 通过 mppx SDK 在 Tempo 链结算 PathUSD/USDC 等稳定币,并支持会话式高频扣款。
代理钱包如何受控?
两种模式:完全由代理自主(开发者持有)与用户持有但代理签名(用户保留撤销权)。每笔交易都会依据附加的策略校验,并提供策略示例、授权密钥、Agent Auth Protocol 与 MCP 桥接的参考文档。

相关技能

以 AI 机器人身份加入视频会议,提供语音、虚拟形象与屏幕共享四种模式。

作者 johnpatternai21 次安装8 星标

按用户明确指令,在得到大脑(Get笔记)中保存、搜索并管理笔记与知识库。

作者 iswalle763 次安装66 星标

把自然语言描述转为结构化 JSON,并由 mcp-diagram-generator MCP 服务生成 Draw.io、Mermaid 或 Excalidraw 图表文件。

作者 nssa.io1.0k 次安装47 星标

在本地磁盘以分类纯 Markdown 文件保存需要长期留存的事实,与智能体内置记忆并存。

作者 Iván1 次安装

从 AdMapix API 拉取广告创意、应用、榜单和收入预估等数据,原样返回结构化 JSON。

作者 fly0pants

tenequm 的更多技能

浏览全部技能

TanStack Query、Router、Start 在 React 全栈项目中的类型安全参考模式。

作者 tenequm22 次安装1 星标

用 MPP 协议在 HTTP 402 上做机器对机器支付,覆盖 TypeScript、Python、Rust 三套 SDK。

作者 tenequm20 次安装1 星标

构建高质量 Agent Skills 的实操指南,覆盖 SKILL.md 结构、frontmatter、描述写法与单文件 / references/ 取舍。

作者 tenequm24 次安装

Lance v11.0.0-beta.6 与 Rust/Python 引擎的固定版本参考资料,同时覆盖 v10.0.0 稳定线。

作者 tenequm22 次安装

用 Wrangler CLI 在 Cloudflare 全球边缘网络上开发并部署 JavaScript、TypeScript、Python 或 Rust 代码。

作者 tenequm20 次安装

用 Swift 6.3 构建原生 macOS 应用,覆盖 SwiftUI、SwiftData、并发与端侧 AI。

作者 tenequm19 次安装