Skip to content

Update defaults to smart wallet - #622

Merged
CarsonRoscoe merged 15 commits into
mainfrom
feat/defaults-to-smart-wallet
Mar 28, 2025
Merged

Update defaults to smart wallet#622
CarsonRoscoe merged 15 commits into
mainfrom
feat/defaults-to-smart-wallet

Conversation

@CarsonRoscoe

@CarsonRoscoe CarsonRoscoe commented Mar 27, 2025

Copy link
Copy Markdown
Contributor

Description

To update all reasonable examples from using CDP server wallets as the default, to using CDP smart wallets.

The smart wallet chatbots were first modified to have two devx improvements:

  1. They now save wallet_data files per-network, to allow builders to swap between networks much easier.
  2. They will also generate private keys if not provided

The affected examples are:
/python/examples/langchain-smart-wallet-chatbot (improved)
/python/examples/langchain-twitter-chatbot
/python/examples/openai-agents-sdk-smart-wallet-chatbot
/typescript/lexamples/angchain-smart-wallet-chatbot (improved)
/typescript/examples/model-context-protocol-smart-wallet-server
/typescript/examples/vercel-ai-sdk-smart-wallet-chatbot

The affected cli commands are:
pipx run create-onchain-agent
npm create onchain-agent
agentkit generate prepare

Also, changed all docs that were pointing to cdp-chatbots as the examples, to instead look at smart-wallet-chatbot examples

Also, minor fixes included are:

  • The npm mcp template was using a different Viem version than the core agentkit package
  • The npm next template was using a different Viem version than the core agentkit package

Note about Twitter:
I did not update the typescript Twitter example because it does not specify a wallet provider. It's a very minimal example that allows it to default. However, on the Python side, it did specify a wallet provider, so I felt it did need to be updated. If I'm going to put in the work to not make that explicitly call out CdpWalletProvider in the example, I might as well switch it to using smart wallets so it inherits the other benefits such as the wallet persistence improvement

Tests

/python/examples/langchain-smart-wallet-chatbot

Starting chat mode... Type 'exit' to end.

Prompt: What is your network, address and wallet provider type

-------------------
Wallet Details:
- Provider: cdp_smart_wallet_provider
- Address: 0x12FC790A93BAE3233D1FDAc3763697d23db9fA7D
- Network:
  * Protocol Family: evm
  * Network ID: base-sepolia
  * Chain ID: 84532
- Native Balance: 0
-------------------
My network is **base-sepolia**, and my wallet address is **0x12FC790A93BAE3233D1FDAc3763697d23db9fA7D**. The wallet provider type is **cdp_smart_wallet_provider**. 

Since I'm on the base-sepolia network and have a zero balance, I can request test tokens from the faucet. Would you like me to do that?

/python/examples/langchain-twitter-chatbot

Starting chat mode... Type 'exit' to end.

Prompt: In your wallet details, what is your wallet provider and address?

-------------------
Wallet Details:
- Provider: cdp_smart_wallet_provider
- Address: 0x12FC790A93BAE3233D1FDAc3763697d23db9fA7D
- Network:
  * Protocol Family: evm
  * Network ID: base-sepolia
  * Chain ID: 84532
- Native Balance: 0
-------------------
My wallet provider is `cdp_smart_wallet_provider`, and my wallet address is `0x12FC790A93BAE3233D1FDAc3763697d23db9fA7D`. I am currently on the Base Sepolia network.
-------------------

/python/examples/openai-agents-sdk-smart-wallet-chatbot

Starting chat mode... Type 'exit' to end.

Prompt: In your wallet details, what is your wallet provider? Also, what is your address
My wallet provider is `cdp_smart_wallet_provider`, and my address is `0xCB066D4932A4dB0B9B3B10C4A74434c60aA79F52`.

typescript/examples/langchain-smart-wallet-chatbot

Starting chat mode... Type 'exit' to end.

Prompt: What is your address and network?

-------------------
Wallet Details:
- Provider: cdp_smart_wallet_provider
- Address: 0xf79C6508fab00F6cD1655948b99B3ba3ac73164A
- Network:
  * Protocol Family: evm
  * Network ID: base-sepolia
  * Chain ID: 84532
- Native Balance: 0 WEI
-------------------
My address is `0xf79C6508fab00F6cD1655948b99B3ba3ac73164A` and I'm currently on the `base-sepolia` network. How can I assist you further?
-------------------

typescript/examples/vercel-ai-sdk-smart-wallet-chatbot

Starting chat mode... Type 'exit' to end.

Prompt: what is your network and address?
My wallet address is **0xAF69EdEA098a46b49F1e7f889D2298852654212a**, and I am currently on the **base-sepolia** network.
-------------------

Prompt: What is your wallet provider?
My wallet provider is Coinbase.
-------------------

Prompt: Give me ALL your network details, including wallet details' provider
Here are all my network details:

- **Provider:** cdp_smart_wallet_provider
- **Address:** 0xAF69EdEA098a46b49F1e7f889D2298852654212a
- **Network:**
  - **Protocol Family:** EVM
  - **Network ID:** base-sepolia
  - **Chain ID:** 84532
- **Native Balance:** 0 WEI

typescript/examples/model-context-protocol-smart-wallet-server

Screenshot 2025-03-28 at 11 19 01 AM

pipx run create-onchain-agent

Screenshot 2025-03-28 at 11 23 11 AM

npm create onchain-agent

Screenshot 2025-03-28 at 11 20 29 AM

agentkit generate prepare

Screenshot 2025-03-28 at 11 20 49 AM

Checklist

A couple of things to include in your PR for completeness:

  • Added documentation to all relevant README.md files
  • Added a changelog entry

@cb-heimdall

cb-heimdall commented Mar 27, 2025

Copy link
Copy Markdown

✅ Heimdall Review Status

Requirement Status More Info
Reviews 1/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@github-actions github-actions Bot added documentation Improvements or additions to documentation example New example agent framework extension New framework extension python typescript labels Mar 27, 2025
@CarsonRoscoe
CarsonRoscoe force-pushed the feat/defaults-to-smart-wallet branch from 764e918 to d7bfcd9 Compare March 27, 2025 23:34
@CarsonRoscoe
CarsonRoscoe force-pushed the feat/defaults-to-smart-wallet branch from d7bfcd9 to 764a6ae Compare March 27, 2025 23:48
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

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


if (!process.env.PRIVATE_KEY || !process.env.SMART_WALLET_ADDRESS) {
console.log("Save your private key and smart wallet address to the environment variables");
console.log("PRIVATE_KEY=" + privateKey);

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.

Since we're now generating the private key if none provided, and McpServers do not have the permission to write files to the file system, we log it so the user has a chance to save the key for reuse

@CarsonRoscoe
CarsonRoscoe marked this pull request as ready for review March 28, 2025 15:26
@CarsonRoscoe
CarsonRoscoe requested a review from 0xRAG March 28, 2025 15:26
Comment thread typescript/.changeset/kind-terms-spend.md Outdated
Comment thread typescript/examples/model-context-protocol-smart-wallet-server/package.json Outdated
apiKeyName: process.env.CDP_API_KEY_NAME!,
apiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY!,
networkId: process.env.NETWORK_ID || "base-sepolia",
smartWalletAddress: process.env.SMART_WALLET_ADDRESS! as Address,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SMART_WALLET_ADDRESS is optional, should we get the address from the generated key in the case that it's not provided?

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'll remove the !, as its unnecessary.

If SMART_WALLET_ADDRESS is not provided, one will be generated, so no concerns there. In that case, we export the generated wallet address from the provider and log it below this code

@CarsonRoscoe
CarsonRoscoe merged commit 1076bb6 into main Mar 28, 2025
@CarsonRoscoe
CarsonRoscoe deleted the feat/defaults-to-smart-wallet branch March 28, 2025 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation example New example agent framework extension New framework extension python typescript

Development

Successfully merging this pull request may close these issues.

3 participants