CDP Agentkit Langchain Extension
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
CDP Agentkit Extension - Langchain Toolkit
CDP integration with Langchain to enable agentic workflows using the core primitives defined in cdp-agentkit-core.
This toolkit contains tools that enable an LLM agent to interact with the Coinbase Developer Platform. The toolkit provides a wrapper around the CDP SDK, allowing agents to perform onchain operations like transfers, trades, and smart contract interactions.
Setup
Prerequisites
- CDP API Key
- OpenAI API Key
- Python 3.10 or higher
Installation
pip install cdp-langchain
Environment Setup
Set the following environment variables:
export CDP_API_KEY_NAME=<your-api-key-name>
export CDP_API_KEY_PRIVATE_KEY=$'<your-private-key>'
export OPENAI_API_KEY=<your-openai-api-key>
export NETWORK_ID=base-sepolia # Optional: Defaults to base-sepolia
Usage
Basic Setup
from cdp_langchain.agent_toolkits import CdpToolkit
from cdp_langchain.utils import CdpAgentkitWrapper
# Initialize CDP wrapper
cdp = CdpAgentkitWrapper()
# Create toolkit from wrapper
toolkit = CdpToolkit.from_cdp_agentkit_wrapper(cdp)
# Get available tools
tools = toolkit.get_tools()
for tool in tools:
print(tool.name)
The toolkit provides the following tools:
- address_reputation - Retrieve the address's reputation on a given network
- deploy_contract - Deploy an arbitrary contract using the Solidity compiler
- deploy_nft - Deploy new NFT contracts
- deploy_token - Deploy ERC-20 token contracts
- get_balance - Get balance for specific assets
- get_balance_nft - Get balance for specific NFTs (ERC-721)
- get_wallet_details - Get details about the MPC Wallet
- mint_nft - Mint NFTs from existing contracts
- morpho_deposit - Deposit into a morpho vault
- morpho_withdraw - Withdraw from a morpho vault
- pyth_fetch_price - Fetch the price of a given price feed from Pyth Network
- pyth_fetch_price_feed_id - Fetch the price feed ID for a given token symbol from Pyth Network
- register_basename - Register a basename for the wallet
- request_faucet_funds - Request test tokens from faucet
- superfluid_create_flow - Create a flow using Superfluid
- superfluid_update_flow - Update a flow using Superfluid
- superfluid_delete_flow - Delete a flow using Superfluid
- trade - Trade assets (Mainnet only)
- transfer - Transfer assets between addresses
- transfer_nft - Transfer an NFT (ERC-721)
- wow_buy_token - Buy Zora Wow ERC20 memecoin with ETH
- wow_create_token - Deploy a token using Zora's Wow Launcher (Bonding Curve)
- wow_sell_token - Sell Zora Wow ERC20 memecoin for ETH
- wrap_eth - Wrap ETH to WETH
Using with an Agent
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
# Initialize LLM
llm = ChatOpenAI(model="gpt-4o-mini")
# Get tools and create agent
tools = toolkit.get_tools()
agent_executor = create_react_agent(llm, tools)
# Example usage
events = agent_executor.stream(
{"messages": [("user", "Send 0.005 ETH to john2879.base.eth")]},
stream_mode="values"
)
for event in 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 that persists 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 supports multiple networks.
Gasless Transactions
The following operations support gasless transactions on Base Mainnet:
- USDC transfers
- EURC transfers
- cbBTC transfers
Examples
Check out cdp-langchain/examples for inspiration and help getting started!
- Chatbot Python: Simple example of a Python Chatbot that can perform complex onchain interactions, using OpenAI.
Contributing
See CONTRIBUTING.md for detailed setup instructions and contribution guidelines.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cdp_langchain-0.0.13.tar.gz.
File metadata
- Download URL: cdp_langchain-0.0.13.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e36badd1a632eb7823b20ef093405b45af185470c79dd2b4a8a7db869d3e2869
|
|
| MD5 |
c85458ad501a4569254a32c44fda8c2e
|
|
| BLAKE2b-256 |
d6a1c6828c4cbdbb27435b864227d2c779a921df636bc3f36e057600a9323769
|
File details
Details for the file cdp_langchain-0.0.13-py3-none-any.whl.
File metadata
- Download URL: cdp_langchain-0.0.13-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52f918b0df4f7dae20d29cef3b83bc1239e054ff46721355ab9a8875b2079cc4
|
|
| MD5 |
6b8635bd084947951d94fb1a4bacf01f
|
|
| BLAKE2b-256 |
0327163c8374db3edf3e0a2896622df151bb0d714ba9b187f13563cfa19d5712
|