Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
OurBuilding Ambient Agents with LangGraph course is now available on LangChain Academy!
Open In ColabOpen on GitHub

CDP Agentkit Toolkit

TheCDP Agentkit toolkit contains tools that enable an LLM agent to interact with theCoinbase Developer Platform. The toolkit provides a wrapper around the CDP SDK, allowing agents to perform onchain operations like transfers, trades, and smart contract interactions.

Overview

Integration details

ClassPackageSerializableJS supportPackage latest
CdpToolkitcdp-langchainPyPI - Version

Tool features

The toolkit provides the following tools:

  1. get_wallet_details - Get details about the MPC Wallet
  2. get_balance - Get balance for specific assets
  3. request_faucet_funds - Request test tokens from faucet
  4. transfer - Transfer assets between addresses
  5. trade - Trade assets (Mainnet only)
  6. deploy_token - Deploy ERC-20 token contracts
  7. mint_nft - Mint NFTs from existing contracts
  8. deploy_nft - Deploy new NFT contracts
  9. register_basename - Register a basename for the wallet

We encourage you to add your own tools, both using CDP and web2 APIs, to create an agent that is tailored to your needs.

Setup

At a high-level, we will:

  1. Install the langchain package
  2. Set up your CDP API credentials
  3. Initialize the CDP wrapper and toolkit
  4. Pass the tools to your agent withtoolkit.get_tools()

To enable automated tracing of individual tools, set yourLangSmith API key:

# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
# os.environ["LANGSMITH_TRACING"] = "true"

Installation

This toolkit lives in thecdp-langchain package:

%pip install-qU cdp-langchain

Set Environment Variables

To use this toolkit, you must first set the following environment variables to access theCDP APIs to create wallets and interact onchain. You can sign up for an API key for free on theCDP Portal:

import getpass
import os

for env_varin[
"CDP_API_KEY_NAME",
"CDP_API_KEY_PRIVATE_KEY",
]:
ifnot os.getenv(env_var):
os.environ[env_var]= getpass.getpass(f"Enter your{env_var}: ")

# Optional: Set network (defaults to base-sepolia)
os.environ["NETWORK_ID"]="base-sepolia"# or "base-mainnet"

Instantiation

Now we can instantiate our toolkit:

from cdp_langchain.agent_toolkitsimport CdpToolkit
from cdp_langchain.utilsimport CdpAgentkitWrapper

# Initialize CDP wrapper
cdp= CdpAgentkitWrapper()

# Create toolkit from wrapper
toolkit= CdpToolkit.from_cdp_agentkit_wrapper(cdp)

Tools

Viewavailable tools:

tools= toolkit.get_tools()
for toolin tools:
print(tool.name)

Use within an agent

We will need a LLM or chat model:

from langchain_openaiimport ChatOpenAI

llm= ChatOpenAI(model="gpt-4o-mini")
API Reference:ChatOpenAI

Initialize the agent with the tools:

from langgraph.prebuiltimport create_react_agent

tools= toolkit.get_tools()
agent_executor= create_react_agent(llm, tools)
API Reference:create_react_agent

Example usage:

example_query="Send 0.005 ETH to john2879.base.eth"

events= agent_executor.stream(
{"messages":[("user", example_query)]},
stream_mode="values",
)
for eventin events:
event["messages"][-1].pretty_print()

Expected output:

Transferred 0.005 of eth to john2879.base.eth.
Transaction hash for the transfer: 0x78c7c2878659a0de216d0764fc87eff0d38b47f3315fa02ba493a83d8e782d1e
Transaction link for the transfer: https://sepolia.basescan.org/tx/0x78c7c2878659a0de216d0764fc87eff0d38b47f3315fa02ba493a83d8e782d1

CDP Toolkit Specific Features

Wallet Management

The toolkit maintains an MPC wallet. The wallet data can be exported and imported to persist between sessions:

# Export wallet data
wallet_data= cdp.export_wallet()

# Import wallet data
values={"cdp_wallet_data": wallet_data}
cdp= CdpAgentkitWrapper(**values)

Network Support

The toolkit supportsmultiple networks

Gasless Transactions

Some operations support gasless transactions on Base Mainnet:

  • USDC transfers
  • EURC transfers
  • cbBTC transfers

API reference

For detailed documentation of all CDP features and configurations head to theCDP docs.

Related


[8]ページ先頭

©2009-2025 Movatter.jp