> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Privy 集成

> 使用 LangChain Python 与 Privy 工具集成。

[Privy](https://privy.io) 是为 AI 智能体设计的强大钱包基础设施，专为可扩展性构建。

## 概述

创建能够：

* 自动创建和管理钱包
* 在多种数字资产中执行支付，包括稳定币
* 签名消息和交易
* 查询钱包余额和地址

### 工作原理

Privy 提供钱包基础设施，简化了区块链交互的复杂性：

1. 为您的智能体提供强大的钱包
2. 通过交易策略保护您的智能体资产
3. 高速执行支付

**零摩擦化快速上手**
与传统钱包解决方案不同，Privy 自动为您的智能体创建嵌入式钱包，无需管理私钥、助记词或复杂设置。

**生产级基础设施**
被领先的 Web3 应用所信赖，Privy 在规模化处理中负责安全密钥生成、多链地址派生、交易签名和合规策略。

### 快速入门

```python theme={null}
import os
from langchain_privy import PrivyWalletTool
from langchain.agents import create_agent

# Set credentials
os.environ["PRIVY_APP_ID"] = "your-privy-app-id"
os.environ["PRIVY_APP_SECRET"] = "your-privy-app-secret"

# Initialize wallet tool (automatically creates wallet)
privy_tool = PrivyWalletTool()
print(f"Wallet created! Address: {privy_tool.wallet_address}")

# Create agent
agent = create_agent(
    model="claude-sonnet-4-6",
    tools=[privy_tool],
)

# Agent can now perform wallet operations
agent.invoke({"messages": [{"role": "user", "content": "What's my wallet address on Base?"}]})
```

查看完整的 [示例](https://github.com/privy-io/langchain-privy/tree/main/examples) 以获取完整实现。

## 设置

前往 [Privy 的控制面板](https://dashboard.privy.io) 注册并创建新应用。您将获得：

* **应用 ID** - 您的应用标识符
* **应用密钥** - 您的服务器端认证密钥

1. 安装包：

```bash theme={null}
pip install langchain-privy
```

2. 设置您的凭证：

```python theme={null}
import os
import getpass

os.environ["PRIVY_APP_ID"] = getpass.getpass("Enter your Privy App ID: ")
os.environ["PRIVY_APP_SECRET"] = getpass.getpass("Enter your Privy App Secret: ")
```

## 实例化

```python theme={null}
from langchain_privy import PrivyWalletTool

# Automatically creates a new Ethereum wallet
tool = PrivyWalletTool()

# Or create on a specific chain
base_tool = PrivyWalletTool(chain_type="base")
solana_tool = PrivyWalletTool(chain_type="solana")

# Or reuse an existing wallet
existing_tool = PrivyWalletTool(wallet_id="wal_abc123...")
```

## 调用

### 可用操作

```python theme={null}
# Get wallet address for any chain
tool.invoke({
    "operation": "get_wallet_address",
    "chain": "base"
})

# Sign a message
tool.invoke({
    "operation": "sign_message",
    "message": "Hello from LangChain!",
    "chain": "ethereum"
})

# Check balance
tool.invoke({
    "operation": "get_balance",
    "chain": "base"
})

# Send transaction
tool.invoke({
    "operation": "send_transaction",
    "chain": "base",
    "to": "0x1234567890123456789012345678901234567890",
    "value": "0.001",
    "unit": "ether"
})
```

## 在智能体中使用

```python theme={null}
import os
from langchain_privy import PrivyWalletTool
from langchain.agents import create_agent

# Set credentials
os.environ["PRIVY_APP_ID"] = "your-privy-app-id"
os.environ["PRIVY_APP_SECRET"] = "your-privy-app-secret"

# Initialize tools
tools = [PrivyWalletTool()]

# Create agent
agent = create_agent(
    model="claude-sonnet-4-6",
    tools=tools,
)

# Natural language wallet operations
agent.invoke({
    "messages": [{"role": "user", "content": "Sign the message 'Verified by AI Agent' and then check my balance on Base"}]
})
```

***

## API 参考

* 完整文档请参阅 [langchain-privy GitHub 仓库](https://github.com/privy-io/langchain-privy)
* 更多关于 Privy 的信息，请参阅 [Privy 文档](https://docs.privy.io)

***

> 官方原文：[src/oss/python/integrations/tools/privy.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/python/integrations/tools/privy.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.