Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Prompt: <prompt>
For example:

```
Chatbot: typescript/examples/langchain-cdp-chatbot/chatbot.ts
Chatbot: typescript/examples/langchain-smart-wallet-chatbot/chatbot.ts
Network: Base Sepolia
Setup: Fauceted with 1 USDC

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
**/__pycache__/

# Wallet data
**/wallet_data.txt
**/wallet_data*

# Tools
**/.pytest_cache
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING-PYTHON.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Integrations into AI Agent frameworks are specific to the framework itself, so w

### Local Testing

A good way to test new actions locally is by using the chatbot example in `python/examples/langchain-cdp-chatbot`. See the [chatbot README](./python/examples/langchain-cdp-chatbot/README.md) for instructions on setting up and running the chatbot.
A good way to test new actions locally is by using the chatbot example in `python/examples/langchain-smart-wallet-chatbot`. See the [chatbot README](./python/examples/langchain-smart-wallet-chatbot/README.md) for instructions on setting up and running the chatbot.

The flow is:

Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING-TYPESCRIPT.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ Integrations into AI Agent frameworks are specific to the framework itself, so w

### Local Testing

A good way to test new actions locally is by using the chatbot example in `typescript/examples/langchain-cdp-chatbot`. See the [chatbot README](https://github.com/coinbase/agentkit/blob/master/typescript/examples/langchain-cdp-chatbot/README.md) for instructions on setting up and running the chatbot.
A good way to test new actions locally is by using the chatbot example in `typescript/examples/langchain-smart-wallet-chatbot`. See the [chatbot README](https://github.com/coinbase/agentkit/blob/master/typescript/examples/langchain-smart-wallet-chatbot/README.md) for instructions on setting up and running the chatbot.

The flow is:

1. Make your change as described in the [Adding an Agentic Action](#adding-an-agentic-action) section
2. From `typescript/`, run `pnpm run build && pnpm i`
3. In `typescript/examples/langchain-cdp-chatbot`, run `pnpm run start`
2. From `typescript/`, run `pnpm i && pnpm build`
3. In `typescript/examples/langchain-smart-wallet-chatbot`, run `pnpm run start`
4. You can now interact with your new action via the chatbot!

### Running Tests
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ agentkit/
│ ├── langchain-privy-chatbot/
│ ├── langchain-solana-chatbot/
│ ├── langchain-twitter-chatbot/
│ ├── model-context-protocol-cdp-server/
│ └── vercel-ai-sdk-cdp-chatbot/
│ ├── model-context-protocol-smart-wallet-server/
│ └── vercel-ai-sdk-smart-wallet-chatbot/
├── python/
│ ├── coinbase-agentkit/
│ ├── create-onchain-agent/
Expand All @@ -47,7 +47,7 @@ agentkit/
│ └── examples/
│ ├── langchain-cdp-chatbot/
│ ├── langchain-twitter-chatbot/
│ └── openai-agents-sdk-cdp-chatbot/
│ └── openai-agents-sdk-smart-wallet-chatbot/
```

## Language-Specific Guides
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ agentkit/
│ ├── langchain-privy-chatbot/
│ ├── langchain-solana-chatbot/
│ ├── langchain-twitter-chatbot/
│ ├── model-context-protocol-cdp-server/
│ └── vercel-ai-sdk-cdp-chatbot/
│ ├── model-context-protocol-smart-wallet-server/
│ └── vercel-ai-sdk-smart-wallet-chatbot/
├── python/
│ ├── coinbase-agentkit/
│ ├── create-onchain-agent/
Expand All @@ -161,7 +161,7 @@ agentkit/
│ └── examples/
│ ├── langchain-cdp-chatbot/
│ ├── langchain-twitter-chatbot/
│ └── openai-agents-sdk-cdp-chatbot/
│ └── openai-agents-sdk-smart-wallet-chatbot/
```

## 🤝 Contributing
Expand Down
1 change: 1 addition & 0 deletions python/create-onchain-agent/changelog.d/622.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated default wallet provider to SmartWalletProvider
4 changes: 2 additions & 2 deletions python/create-onchain-agent/create_onchain_agent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ def create_advanced_project(templates_path: str | None = None):
if network:
if network in CDP_SUPPORTED_NETWORKS:
wallet_choices = [
"CDP Wallet Provider",
"Smart Wallet Provider",
"CDP Wallet Provider",
"Ethereum Account Wallet Provider",
]
wallet_selection = questionary.select(
"Select a wallet provider:",
choices=wallet_choices,
default="CDP Wallet Provider",
default="Smart Wallet Provider",
style=custom_style,
).ask()

Expand Down
14 changes: 6 additions & 8 deletions python/examples/langchain-smart-wallet-chatbot/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,32 @@
from langgraph.checkpoint.memory import MemorySaver
from langgraph.prebuilt import create_react_agent

wallet_data_file = "wallet_data.txt"

load_dotenv()


def initialize_agent():
"""Initialize the agent with SmartWalletProvider."""
llm = ChatOpenAI(model="gpt-4o-mini")

network_id = os.getenv("NETWORK_ID", "base-sepolia")
wallet_data_file = f"wallet_data_{network_id.replace('-', '_')}.txt"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to improve the smart wallet examples before I copied their code into other examples.

This improvement is regarding switching networks. Now, rather than a wallet_data.txt file that cannot change networks, each network will generate a different wallet file, e.g. wallet_data_base_sepolia.txt and wallet_data_base_mainnet.txt


# Load wallet data from JSON file
wallet_data = {"private_key": None, "smart_wallet_address": None}
if os.path.exists(wallet_data_file):
try:
with open(wallet_data_file) as f:
wallet_data = json.load(f)
except json.JSONDecodeError:
print("Warning: Invalid wallet data file format. Creating new wallet.")
print(f"Warning: Invalid wallet data file format for {network_id}. Creating new wallet.")

# Use private key from env if not in wallet data
private_key = wallet_data.get("private_key") or os.getenv("PRIVATE_KEY")

if not private_key:
raise ValueError("PRIVATE_KEY environment variable is required")
acct = Account.create()
private_key = acct.key.hex()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another generate improvement. If a private key is not set, generate one instead of throw an error


signer = Account.from_key(private_key)

network_id = os.getenv("NETWORK_ID", "base-sepolia")

# Initialize CDP Wallet Provider
wallet_provider = SmartWalletProvider(
SmartWalletProviderConfig(
Expand Down
53 changes: 37 additions & 16 deletions python/examples/langchain-twitter-chatbot/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
from coinbase_agentkit import (
AgentKit,
AgentKitConfig,
CdpWalletProvider,
CdpWalletProviderConfig,
SmartWalletProvider,
SmartWalletProviderConfig,
twitter_action_provider,
wallet_action_provider,
)
from coinbase_agentkit_langchain import get_langchain_tools
from dotenv import load_dotenv
from eth_account.account import Account
from langchain_core.messages import HumanMessage
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import MemorySaver
Expand All @@ -29,17 +30,42 @@ def initialize_agent():
# Initialize LLM
llm = ChatOpenAI(model="gpt-4o-mini")

# Initialize CDP Wallet Provider
wallet_data = None
# Load wallet data from JSON file
network_id = os.getenv("NETWORK_ID", "base-sepolia")
wallet_data_file = f"wallet_data_{network_id.replace('-', '_')}.txt"
wallet_data = {"private_key": None, "smart_wallet_address": None}
if os.path.exists(wallet_data_file):
with open(wallet_data_file) as f:
wallet_data = f.read()

cdp_config = None
if wallet_data is not None:
cdp_config = CdpWalletProviderConfig(wallet_data=wallet_data)
try:
with open(wallet_data_file) as f:
wallet_data = json.load(f)
except json.JSONDecodeError:
print(f"Warning: Invalid wallet data file format for {network_id}. Creating new wallet.")

# Use private key from env if not in wallet data
private_key = wallet_data.get("private_key") or os.getenv("PRIVATE_KEY")
if not private_key:
acct = Account.create()
private_key = acct.key.hex()

signer = Account.from_key(private_key)

# Initialize Smart Wallet Provider
wallet_provider = SmartWalletProvider(
SmartWalletProviderConfig(
network_id=network_id,
signer=signer,
smart_wallet_address=wallet_data.get("smart_wallet_address"),
paymaster_url=None, # Sponsor transactions: https://docs.cdp.coinbase.com/paymaster/docs/welcome
)
)

wallet_provider = CdpWalletProvider(cdp_config)
# Save both private key and smart wallet address
wallet_data = {
"private_key": private_key,
"smart_wallet_address": wallet_provider.get_address(),
}
with open(wallet_data_file, "w") as f:
json.dump(wallet_data, f, indent=2)

agentkit = AgentKit(
AgentKitConfig(
Expand All @@ -51,11 +77,6 @@ def initialize_agent():
)
)

wallet_data_json = json.dumps(wallet_provider.export_wallet().to_dict())

with open(wallet_data_file, "w") as f:
f.write(wallet_data_json)

# use get_langchain_tools
tools = get_langchain_tools(agentkit)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CDP_API_KEY_NAME= # Place your CDP API key name here
CDP_API_KEY_PRIVATE_KEY= # Place your CDP API key private key here
OPENAI_API_KEY= # Place your OpenAI API key here
PRIVATE_KEY= # Place your private key here
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ poetry install
- "CDP_API_KEY_NAME"
- "CDP_API_KEY_PRIVATE_KEY"
- "OPENAI_API_KEY"
- "PRIVATE_KEY" (optional, will generate a new private key if not provided)
- "NETWORK_ID" (Defaults to `base-sepolia`)

```bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
from coinbase_agentkit import (
AgentKit,
AgentKitConfig,
CdpWalletProvider,
CdpWalletProviderConfig,
SmartWalletProvider,
SmartWalletProviderConfig,
cdp_api_action_provider,
cdp_wallet_action_provider,
erc20_action_provider,
pyth_action_provider,
wallet_action_provider,
weth_action_provider,
)
from coinbase_agentkit_openai_agents_sdk import get_openai_agents_sdk_tools
from dotenv import load_dotenv
from eth_account.account import Account
from agents.agent import Agent
from agents.run import Runner

Expand All @@ -28,25 +28,50 @@


def initialize_agent():
"""Initialize the agent with CDP Agentkit."""
# Initialize CDP Wallet Provider
wallet_data = None
if os.path.exists(wallet_data_file):
with open(wallet_data_file) as f:
wallet_data = f.read()
"""Initialize the agent with SmartWalletProvider."""
network_id = os.getenv("NETWORK_ID", "base-sepolia")
wallet_data_file = f"wallet_data_{network_id.replace('-', '_')}.txt"

cdp_config = None
if wallet_data is not None:
cdp_config = CdpWalletProviderConfig(wallet_data=wallet_data)
# Load wallet data from JSON file
wallet_data = {"private_key": None, "smart_wallet_address": None}
if os.path.exists(wallet_data_file):
try:
with open(wallet_data_file) as f:
wallet_data = json.load(f)
except json.JSONDecodeError:
print(f"Warning: Invalid wallet data file format for {network_id}. Creating new wallet.")

# Use private key from env if not in wallet data
private_key = wallet_data.get("private_key") or os.getenv("PRIVATE_KEY")
if not private_key:
acct = Account.create()
private_key = acct.key.hex()

signer = Account.from_key(private_key)

# Initialize Smart Wallet Provider
wallet_provider = SmartWalletProvider(
SmartWalletProviderConfig(
network_id=network_id,
signer=signer,
smart_wallet_address=wallet_data.get("smart_wallet_address"),
paymaster_url=None, # Sponsor transactions: https://docs.cdp.coinbase.com/paymaster/docs/welcome
)
)

wallet_provider = CdpWalletProvider(cdp_config)
# Save both private key and smart wallet address
wallet_data = {
"private_key": private_key,
"smart_wallet_address": wallet_provider.get_address(),
}
with open(wallet_data_file, "w") as f:
json.dump(wallet_data, f, indent=2)

agentkit = AgentKit(
AgentKitConfig(
wallet_provider=wallet_provider,
action_providers=[
cdp_api_action_provider(),
cdp_wallet_action_provider(),
erc20_action_provider(),
pyth_action_provider(),
wallet_action_provider(),
Expand All @@ -55,11 +80,6 @@ def initialize_agent():
)
)

wallet_data_json = json.dumps(wallet_provider.export_wallet().to_dict())

with open(wallet_data_file, "w") as f:
f.write(wallet_data_json)

# use get_openai_agents_sdk_tools
tools = get_openai_agents_sdk_tools(agentkit)

Expand Down
2 changes: 1 addition & 1 deletion python/framework-extensions/langchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ agent = create_react_agent(

For AgentKit configuration options, see the [Coinbase Agentkit README](https://github.com/coinbase/agentkit/blob/master/python/coinbase-agentkit/README.md).

For a full example, see the [chatbot example](https://github.com/coinbase/agentkit/blob/master/python/examples/langchain-cdp-chatbot/chatbot.py).
For a full example, see the [chatbot example](https://github.com/coinbase/agentkit/blob/master/python/examples/langchain-smart-wallet-chatbot/chatbot.py).

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion python/framework-extensions/openai-agents-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ agent = Agent(

For AgentKit configuration options, see the [Coinbase Agentkit README](https://github.com/coinbase/agentkit/blob/master/python/coinbase-agentkit/README.md).

For a full example, see the [chatbot example](https://github.com/coinbase/agentkit/blob/master/python/examples/openai-agents-sdk-cdp-chatbot/chatbot.py).
For a full example, see the [chatbot example](https://github.com/coinbase/agentkit/blob/master/python/examples/openai-agents-sdk-smart-wallet-chatbot/chatbot.py).

## Contributing

Expand Down
5 changes: 5 additions & 0 deletions typescript/.changeset/kind-terms-spend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-onchain-agent": minor
---

Updated default wallet provider to SmartWalletProvider
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ export async function initProject() {
},
message: (prev, { network }) => {
const walletDescriptions: Record<WalletProviderChoice, string> = {
CDP: "Uses Coinbase Developer Platform (CDP)'s managed wallet.",
SmartWallet: "Uses Coinbase Developer Platform (CDP)'s Smart Wallet.",
CDP: "Uses Coinbase Developer Platform (CDP)'s managed wallet.",
Viem: "Client-side Ethereum wallet.",
Privy: "Authentication and wallet infrastructure.",
SolanaKeypair: "Client-side Solana wallet.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export async function prepareAgentKit() {
name: "walletProvider",
message: (prev, { network }) => {
const walletDescriptions: Record<WalletProviderChoice, string> = {
CDP: "Uses Coinbase Developer Platform (CDP)'s managed wallet.",
SmartWallet: "Uses Coinbase Developer Platform (CDP)'s Smart Wallet.",
CDP: "Uses Coinbase Developer Platform (CDP)'s managed wallet.",
Viem: "Client-side Ethereum wallet.",
Privy: "Authentication and wallet infrastructure.",
SolanaKeypair: "Client-side Solana wallet.",
Expand Down
2 changes: 1 addition & 1 deletion typescript/create-onchain-agent/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type SVMNetwork = (typeof SVM_NETWORKS)[number];

export type Network = EVMNetwork | SVMNetwork;

const CDP_SUPPORTED_EVM_WALLET_PROVIDERS = ["CDP", "SmartWallet", "Viem", "Privy"] as const;
const CDP_SUPPORTED_EVM_WALLET_PROVIDERS = ["SmartWallet", "CDP", "Viem", "Privy"] as const;
const SVM_WALLET_PROVIDERS = ["SolanaKeypair", "Privy"] as const;
export const NON_CDP_SUPPORTED_EVM_WALLET_PROVIDERS = ["Viem", "Privy"] as const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@modelcontextprotocol/sdk": "^1.6.1",
"@solana/web3.js": "^1.98.0",
"bs58": "^6.0.0",
"viem": "^2.23.7"
"viem": "^2.24.1"
},
"devDependencies": {
"@types/node": "^22.13.9",
Expand Down
Loading