Update defaults to smart wallet - #622
Conversation
✅ Heimdall Review Status
|
764e918 to
d7bfcd9
Compare
d7bfcd9 to
764a6ae
Compare
| llm = ChatOpenAI(model="gpt-4o-mini") | ||
|
|
||
| network_id = os.getenv("NETWORK_ID", "base-sepolia") | ||
| wallet_data_file = f"wallet_data_{network_id.replace('-', '_')}.txt" |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
| 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, |
There was a problem hiding this comment.
SMART_WALLET_ADDRESS is optional, should we get the address from the generated key in the case that it's not provided?
There was a problem hiding this comment.
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
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:
wallet_datafiles per-network, to allow builders to swap between networks much easier.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-chatbotThe affected cli commands are:
pipx run create-onchain-agentnpm create onchain-agentagentkit generate prepareAlso, 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:
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/python/examples/langchain-twitter-chatbot/python/examples/openai-agents-sdk-smart-wallet-chatbottypescript/examples/langchain-smart-wallet-chatbottypescript/examples/vercel-ai-sdk-smart-wallet-chatbottypescript/examples/model-context-protocol-smart-wallet-serverpipx run create-onchain-agentnpm create onchain-agentagentkit generate prepareChecklist
A couple of things to include in your PR for completeness: