From a14f660f47b6b1bfe6bbde95e1776ad967399b8d Mon Sep 17 00:00:00 2001 From: CarsonRoscoe Date: Sun, 2 Mar 2025 10:57:38 -0800 Subject: [PATCH 01/10] feat: initial draft of improved network selection --- .../create_onchain_agent/cli.py | 174 ++++++++++++------ .../templates/chatbot/.env.local.jinja | 8 + .../templates/chatbot/chatbot.py.jinja | 25 ++- 3 files changed, 154 insertions(+), 53 deletions(-) diff --git a/python/create-onchain-agent/create_onchain_agent/cli.py b/python/create-onchain-agent/create_onchain_agent/cli.py index 4db0b93cf..cbaaab06d 100755 --- a/python/create-onchain-agent/create_onchain_agent/cli.py +++ b/python/create-onchain-agent/create_onchain_agent/cli.py @@ -39,18 +39,24 @@ # "selected": "bold cyan", # Selected option }) -NETWORK_CHOICES = [ - ("Ethereum Mainnet", "ethereum-mainnet"), - ("Ethereum Sepolia", "ethereum-sepolia"), - ("Polygon Mainnet", "polygon-mainnet"), - ("Polygon Mumbai", "polygon-mumbai"), - ("Base Mainnet", "base-mainnet"), - ("Base Sepolia (default)", "base-sepolia"), - ("Arbitrum Mainnet", "arbitrum-mainnet"), - ("Arbitrum Sepolia", "arbitrum-sepolia"), - ("Optimism Mainnet", "optimism-mainnet"), - ("Optimism Sepolia", "optimism-sepolia"), - ("Other (Enter EVM Chain ID)", "other"), +# Network constants +EVM_NETWORKS = [ + ("base-mainnet", "Base Mainnet"), + ("base-sepolia", "Base Sepolia"), + ("ethereum-mainnet", "Ethereum Mainnet"), + ("ethereum-sepolia", "Ethereum Sepolia"), + ("arbitrum-mainnet", "Arbitrum Mainnet"), + ("arbitrum-sepolia", "Arbitrum Sepolia"), + ("optimism-mainnet", "Optimism Mainnet"), + ("optimism-sepolia", "Optimism Sepolia"), + ("polygon-mainnet", "Polygon Mainnet"), + ("polygon-mumbai", "Polygon Mumbai"), +] + +SVM_NETWORKS = [ + ("solana-mainnet", "Solana Mainnet"), + ("solana-devnet", "Solana Devnet"), + ("solana-testnet", "Solana Testnet"), ] CDP_SUPPORTED_NETWORKS = { @@ -94,6 +100,14 @@ def download_and_extract_template(): return str(extract_path) +def get_network_choices(network_type: str) -> list: + """Filter network choices based on network type (mainnet/testnet).""" + return [ + (name, id) for id, name in EVM_NETWORKS + if (network_type == "mainnet" and "mainnet" in id) or + (network_type == "testnet" and any(net in id for net in ["sepolia", "mumbai", "devnet", "testnet"])) + ] + @click.command() def create_project(): """Creates a new onchain agent project with interactive prompts.""" @@ -131,56 +145,112 @@ def create_project(): else: package_name = suggested_package_name - # Select network using arrow keys - # console.print("\n[cyan]Select a network:[/cyan]") - - network_name = questionary.select( - "Choose a network network:", - choices=[name for name, _ in NETWORK_CHOICES], - default="Base Sepolia (default)", - style=custom_style # Apply custom styling + # First, choose network family + network_family = questionary.select( + "Choose a network family:", + choices=[ + "Ethereum Virtual Machine (EVM)", + "Solana Virtual Machine (SVM)", + ], + style=custom_style ).ask() - # Map selection to network key - network = next(n for n in NETWORK_CHOICES if n[0] == network_name)[1] - - # If "Other" is selected, prompt for EVM Chain ID - if network == "other": - network = questionary.text( - "Enter the EVM Chain ID for your custom network:", + network = None + chain_id = None + rpc_url = None + + if network_family == "Ethereum Virtual Machine (EVM)": + # For EVM, choose network type + network_type = questionary.select( + "Choose network type:", + choices=[ + "Mainnet", + "Testnet", + "Custom Chain ID", + ], style=custom_style - ).ask().strip() + ).ask() - # Determine wallet provider - if network in CDP_SUPPORTED_NETWORKS: - wallet_provider = questionary.select( - "Select a wallet provider:", - choices=["CDP Wallet Provider", "Ethereum Account Wallet Provider"], - default="CDP Wallet Provider", - style=custom_style # Apply custom styling + if network_type == "Custom Chain ID": + # Handle custom EVM network + chain_id = questionary.text( + "Enter your chain ID:", + validate=lambda text: text.strip().isdigit() or "Chain ID must be a number", + style=custom_style + ).ask() + + rpc_url = questionary.text( + "Enter your RPC URL:", + validate=lambda text: ( + text.strip().startswith(("http://", "https://")) or + "RPC URL must start with http:// or https://" + ), + style=custom_style + ).ask() + + wallet_provider = "eth" # Default to eth wallet provider for custom networks + else: + # Filter networks based on mainnet/testnet selection + network_choices = get_network_choices(network_type.lower()) + network_name = questionary.select( + "Choose a network:", + choices=[ + name + (" (default)" if id == "base-sepolia" else "") + for name, id in network_choices + ], + default="Base Sepolia (default)" if network_type == "Testnet" else None, + style=custom_style + ).ask() + + # Remove " (default)" suffix if present + network_name = network_name.replace(" (default)", "") + network = next(id for name, id in network_choices if name == network_name) + + else: # SVM + network_name = questionary.select( + "Choose a network:", + choices=[name for _, name in SVM_NETWORKS], + style=custom_style ).ask() + + network = next(id for id, name in SVM_NETWORKS if name == network_name) + wallet_provider = "solana" # Default to Solana wallet provider for SVM + + # Determine wallet provider for non-custom EVM networks + if network and network_family == "Ethereum Virtual Machine (EVM)": + if network in CDP_SUPPORTED_NETWORKS: + wallet_choices = [ + "CDP Wallet Provider", + "Ethereum Account Wallet Provider" + ] + wallet_selection = questionary.select( + "Select a wallet provider:", + choices=wallet_choices, + default="CDP Wallet Provider", + style=custom_style + ).ask() + wallet_provider = "cdp" if wallet_selection.startswith("CDP") else "eth" + else: + console.print(f"[yellow]⚠️ CDP is not supported on {network}. Defaulting to Ethereum Account Wallet Provider.[/yellow]") + wallet_provider = "eth" - wallet_provider = "cdp" if wallet_provider.startswith("CDP") else "eth" - else: - console.print(f"[yellow]⚠️ CDP is not supported on {network}. Defaulting to Ethereum Account Wallet Provider.[/yellow]") - wallet_provider = "eth" + console.print(f"\n[blue]Creating your onchain agent project: {project_name}[/blue]") + # Update the Copier data dict to include new fields + copier_data = { + "_project_name": project_name, + "_package_name": package_name, + "_network": network, + "_wallet_provider": wallet_provider, + } - console.print(f"\n[blue]Creating your onchain agent project: {project_name}[/blue]") + if chain_id: + copier_data["_chain_id"] = chain_id + if rpc_url: + copier_data["_rpc_url"] = rpc_url template_path = download_and_extract_template() - - # Run Copier with collected answers - run_copy( - template_path, - project_path, - data={ - "_project_name": project_name, - "_package_name": package_name, - "_network": network, - "_wallet_provider": wallet_provider, - }, - ) + run_copy(template_path, project_path, data=copier_data) console.print(f"[bold blue]Successfully created your AgentKit project in {project_path}[/bold blue]") diff --git a/python/create-onchain-agent/templates/chatbot/.env.local.jinja b/python/create-onchain-agent/templates/chatbot/.env.local.jinja index 65653e50a..14d21bf1a 100644 --- a/python/create-onchain-agent/templates/chatbot/.env.local.jinja +++ b/python/create-onchain-agent/templates/chatbot/.env.local.jinja @@ -14,7 +14,15 @@ CDP_API_KEY_PRIVATE_KEY= PRIVATE_KEY= {% endif %} ## Optional +{% if _network %} NETWORK={{ _network }} +{% endif %} +{% if _chain_id %} +CHAIN_ID={{ _chain_id }} +{% endif %} +{% if _rpc_url %} +RPC_URL={{ _rpc_url }} +{% endif %} {% if _wallet_provider == "eth" %} # Place your CDP API key name here if you want to use the CDPApiActionProvider CDP_API_KEY_NAME= diff --git a/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja b/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja index 84d7ba6e7..9490f6eba 100644 --- a/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja +++ b/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja @@ -31,6 +31,7 @@ from coinbase_agentkit import ( from coinbase_agentkit_langchain import get_langchain_tools {% if _wallet_provider == "eth" %} from eth_account import Account +from coinbase_agentkit.network import NETWORK_ID_TO_CHAIN_ID, NETWORK_ID_TO_CHAIN {% endif %} """ AgentKit Integration @@ -119,10 +120,32 @@ def initialize_agent(): # Create Ethereum account from private key account = Account.from_key(private_key) + # Get chain configuration + chain_id = os.getenv("CHAIN_ID") + rpc_url = os.getenv("RPC_URL") + network = os.getenv("NETWORK") + + if not chain_id and network: + # If no chain_id provided but network is, derive chain_id from network + chain_id = NETWORK_ID_TO_CHAIN_ID.get(network) + if not chain_id: + raise ValueError(f"Unknown network ID: {network}") + + if not rpc_url and network: + # If no RPC URL provided but network is, get default RPC from chain config + chain = NETWORK_ID_TO_CHAIN.get(network) + if chain: + rpc_url = chain["rpc_urls"]["default"]["http"][0] + + if not chain_id: + # Default to Base Sepolia if no chain_id or network specified + chain_id = "84532" # Base Sepolia chain ID + wallet_provider = EthAccountWalletProvider( config=EthAccountWalletProviderConfig( account=account, - chain_id="84532" + chain_id=chain_id, + rpc_url=rpc_url ) ) {% endif %} From 22bf6462f6b716ad4e86ce33220ac08a7a16c623 Mon Sep 17 00:00:00 2001 From: CarsonRoscoe Date: Mon, 3 Mar 2025 09:18:11 -0500 Subject: [PATCH 02/10] bump agentkit dependency in template --- .../create-onchain-agent/templates/chatbot/pyproject.toml.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/create-onchain-agent/templates/chatbot/pyproject.toml.jinja b/python/create-onchain-agent/templates/chatbot/pyproject.toml.jinja index df25fb9a1..88aa41d89 100644 --- a/python/create-onchain-agent/templates/chatbot/pyproject.toml.jinja +++ b/python/create-onchain-agent/templates/chatbot/pyproject.toml.jinja @@ -11,7 +11,7 @@ python = "^3.10" python-dotenv = "^1.0.1" langchain-openai = "^0.2.4" langgraph = "^0.2.39" -coinbase-agentkit = "0.1.2" +coinbase-agentkit = "0.1.4" coinbase-agentkit-langchain = "0.1.0" [tool.poetry.scripts] From 0517ffd871c65aca61a939ff53ae289b3b2fcf07 Mon Sep 17 00:00:00 2001 From: CarsonRoscoe Date: Mon, 3 Mar 2025 09:18:29 -0500 Subject: [PATCH 03/10] feat: refactor cli so it can build with local template --- .../create_onchain_agent/cli.py | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/python/create-onchain-agent/create_onchain_agent/cli.py b/python/create-onchain-agent/create_onchain_agent/cli.py index cbaaab06d..cf8631903 100755 --- a/python/create-onchain-agent/create_onchain_agent/cli.py +++ b/python/create-onchain-agent/create_onchain_agent/cli.py @@ -70,8 +70,26 @@ VALID_PACKAGE_NAME_REGEX = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*$") -def download_and_extract_template(): - """Downloads and extracts the chatbot template to a persistent location.""" +def get_template_path(development_mode: bool = False) -> str: + """Gets the template path either from local development directory or downloaded from GitHub. + + Args: + development_mode: If True, use local development path instead of downloading from GitHub + + Returns: + str: Path to the template directory + """ + if development_mode: + # Use local development path (relative to this file) + local_template_path = Path(__file__).parent.parent / "templates" / "chatbot" + if not local_template_path.exists(): + raise FileNotFoundError( + f"Local template path not found at {local_template_path}. " + "Make sure you're running from the correct directory in development mode." + ) + return str(local_template_path) + + # Production mode - download from GitHub LOCAL_CACHE_DIR.mkdir(parents=True, exist_ok=True) zip_path = LOCAL_CACHE_DIR / "repo.zip" extract_path = LOCAL_CACHE_DIR / "templates" @@ -109,7 +127,8 @@ def get_network_choices(network_type: str) -> list: ] @click.command() -def create_project(): +@click.option('--development', is_flag=True, help='Use local development template path') +def create_project(development): """Creates a new onchain agent project with interactive prompts.""" ascii_art = """ @@ -249,8 +268,12 @@ def create_project(): if rpc_url: copier_data["_rpc_url"] = rpc_url - template_path = download_and_extract_template() - run_copy(template_path, project_path, data=copier_data) + try: + template_path = get_template_path(development) + run_copy(template_path, project_path, data=copier_data) + except FileNotFoundError as e: + console.print(f"[red]Error: {str(e)}[/red]") + return console.print(f"[bold blue]Successfully created your AgentKit project in {project_path}[/bold blue]") From 9de198644d9d0c5e5ed9601741923e3ab1fff0d4 Mon Sep 17 00:00:00 2001 From: CarsonRoscoe Date: Mon, 3 Mar 2025 09:26:45 -0500 Subject: [PATCH 04/10] feat: refactored development flag into template src flag --- .../create_onchain_agent/cli.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/python/create-onchain-agent/create_onchain_agent/cli.py b/python/create-onchain-agent/create_onchain_agent/cli.py index cf8631903..9f542ea1f 100755 --- a/python/create-onchain-agent/create_onchain_agent/cli.py +++ b/python/create-onchain-agent/create_onchain_agent/cli.py @@ -70,26 +70,26 @@ VALID_PACKAGE_NAME_REGEX = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*$") -def get_template_path(development_mode: bool = False) -> str: - """Gets the template path either from local development directory or downloaded from GitHub. +def get_template_path(template_path: str | None = None) -> str: + """Gets the template path either from a local directory or downloaded from GitHub. Args: - development_mode: If True, use local development path instead of downloading from GitHub + template_path: Optional path to local template directory Returns: str: Path to the template directory """ - if development_mode: - # Use local development path (relative to this file) - local_template_path = Path(__file__).parent.parent / "templates" / "chatbot" + if template_path: + # Use provided template path + local_template_path = Path(template_path) if not local_template_path.exists(): raise FileNotFoundError( - f"Local template path not found at {local_template_path}. " - "Make sure you're running from the correct directory in development mode." + f"Template path not found at {local_template_path}. " + "Please provide a valid template directory path." ) return str(local_template_path) - # Production mode - download from GitHub + # No template provided - download from GitHub LOCAL_CACHE_DIR.mkdir(parents=True, exist_ok=True) zip_path = LOCAL_CACHE_DIR / "repo.zip" extract_path = LOCAL_CACHE_DIR / "templates" @@ -127,8 +127,8 @@ def get_network_choices(network_type: str) -> list: ] @click.command() -@click.option('--development', is_flag=True, help='Use local development template path') -def create_project(development): +@click.option('--template', type=str, help='Path to local template directory', default=None) +def create_project(template): """Creates a new onchain agent project with interactive prompts.""" ascii_art = """ @@ -269,7 +269,7 @@ def create_project(development): copier_data["_rpc_url"] = rpc_url try: - template_path = get_template_path(development) + template_path = get_template_path(template) run_copy(template_path, project_path, data=copier_data) except FileNotFoundError as e: console.print(f"[red]Error: {str(e)}[/red]") From 127cf8a0c00a09c38f9027629c3f56cb094faa38 Mon Sep 17 00:00:00 2001 From: CarsonRoscoe Date: Mon, 3 Mar 2025 09:32:34 -0500 Subject: [PATCH 05/10] chore: changelog --- python/create-onchain-agent/changelog.d/498.feature.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 python/create-onchain-agent/changelog.d/498.feature.md diff --git a/python/create-onchain-agent/changelog.d/498.feature.md b/python/create-onchain-agent/changelog.d/498.feature.md new file mode 100644 index 000000000..108af6c60 --- /dev/null +++ b/python/create-onchain-agent/changelog.d/498.feature.md @@ -0,0 +1 @@ +Added revised network selection From 4fec024d7cfe7c31afeef5c04168cd38e55782ac Mon Sep 17 00:00:00 2001 From: CarsonRoscoe Date: Mon, 3 Mar 2025 09:47:40 -0500 Subject: [PATCH 06/10] fix: removed unsupported networks from selection --- .../create_onchain_agent/cli.py | 97 +++++++------------ 1 file changed, 35 insertions(+), 62 deletions(-) diff --git a/python/create-onchain-agent/create_onchain_agent/cli.py b/python/create-onchain-agent/create_onchain_agent/cli.py index 9f542ea1f..2e932cef3 100755 --- a/python/create-onchain-agent/create_onchain_agent/cli.py +++ b/python/create-onchain-agent/create_onchain_agent/cli.py @@ -53,12 +53,6 @@ ("polygon-mumbai", "Polygon Mumbai"), ] -SVM_NETWORKS = [ - ("solana-mainnet", "Solana Mainnet"), - ("solana-devnet", "Solana Devnet"), - ("solana-testnet", "Solana Testnet"), -] - CDP_SUPPORTED_NETWORKS = { "base-mainnet", "base-sepolia", @@ -164,12 +158,13 @@ def create_project(template): else: package_name = suggested_package_name - # First, choose network family - network_family = questionary.select( - "Choose a network family:", + # Choose network type + network_type = questionary.select( + "Choose network type:", choices=[ - "Ethereum Virtual Machine (EVM)", - "Solana Virtual Machine (SVM)", + "Mainnet", + "Testnet", + "Custom Chain ID", ], style=custom_style ).ask() @@ -178,65 +173,43 @@ def create_project(template): chain_id = None rpc_url = None - if network_family == "Ethereum Virtual Machine (EVM)": - # For EVM, choose network type - network_type = questionary.select( - "Choose network type:", - choices=[ - "Mainnet", - "Testnet", - "Custom Chain ID", - ], + if network_type == "Custom Chain ID": + # Handle custom EVM network + chain_id = questionary.text( + "Enter your chain ID:", + validate=lambda text: text.strip().isdigit() or "Chain ID must be a number", style=custom_style ).ask() - if network_type == "Custom Chain ID": - # Handle custom EVM network - chain_id = questionary.text( - "Enter your chain ID:", - validate=lambda text: text.strip().isdigit() or "Chain ID must be a number", - style=custom_style - ).ask() - - rpc_url = questionary.text( - "Enter your RPC URL:", - validate=lambda text: ( - text.strip().startswith(("http://", "https://")) or - "RPC URL must start with http:// or https://" - ), - style=custom_style - ).ask() - - wallet_provider = "eth" # Default to eth wallet provider for custom networks - else: - # Filter networks based on mainnet/testnet selection - network_choices = get_network_choices(network_type.lower()) - network_name = questionary.select( - "Choose a network:", - choices=[ - name + (" (default)" if id == "base-sepolia" else "") - for name, id in network_choices - ], - default="Base Sepolia (default)" if network_type == "Testnet" else None, - style=custom_style - ).ask() - - # Remove " (default)" suffix if present - network_name = network_name.replace(" (default)", "") - network = next(id for name, id in network_choices if name == network_name) - - else: # SVM + rpc_url = questionary.text( + "Enter your RPC URL:", + validate=lambda text: ( + text.strip().startswith(("http://", "https://")) or + "RPC URL must start with http:// or https://" + ), + style=custom_style + ).ask() + + wallet_provider = "eth" # Default to eth wallet provider for custom networks + else: + # Filter networks based on mainnet/testnet selection + network_choices = get_network_choices(network_type.lower()) network_name = questionary.select( "Choose a network:", - choices=[name for _, name in SVM_NETWORKS], + choices=[ + name + (" (default)" if id == "base-sepolia" else "") + for name, id in network_choices + ], + default="Base Sepolia (default)" if network_type == "Testnet" else None, style=custom_style ).ask() - - network = next(id for id, name in SVM_NETWORKS if name == network_name) - wallet_provider = "solana" # Default to Solana wallet provider for SVM - # Determine wallet provider for non-custom EVM networks - if network and network_family == "Ethereum Virtual Machine (EVM)": + # Remove " (default)" suffix if present + network_name = network_name.replace(" (default)", "") + network = next(id for name, id in network_choices if name == network_name) + + # Determine wallet provider + if network: if network in CDP_SUPPORTED_NETWORKS: wallet_choices = [ "CDP Wallet Provider", From 0be55b7a00515102bf2e94714f822e6b6a54229f Mon Sep 17 00:00:00 2001 From: CarsonRoscoe Date: Mon, 3 Mar 2025 15:27:44 -0500 Subject: [PATCH 07/10] chore: reworked network/chain/rpc logic to be tighter --- .../templates/chatbot/chatbot.py.jinja | 21 +++++++++---------- .../templates/chatbot/pyproject.toml.jinja | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja b/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja index 9490f6eba..f53b3b704 100644 --- a/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja +++ b/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja @@ -125,21 +125,20 @@ def initialize_agent(): rpc_url = os.getenv("RPC_URL") network = os.getenv("NETWORK") - if not chain_id and network: - # If no chain_id provided but network is, derive chain_id from network + if chain_id and rpc_url: + pass + elif network: chain_id = NETWORK_ID_TO_CHAIN_ID.get(network) if not chain_id: raise ValueError(f"Unknown network ID: {network}") - - if not rpc_url and network: - # If no RPC URL provided but network is, get default RPC from chain config - chain = NETWORK_ID_TO_CHAIN.get(network) - if chain: + + if not rpc_url: + chain = NETWORK_ID_TO_CHAIN[network] rpc_url = chain["rpc_urls"]["default"]["http"][0] - - if not chain_id: - # Default to Base Sepolia if no chain_id or network specified - chain_id = "84532" # Base Sepolia chain ID + elif chain_id: + raise ValueError("When using chain_id, you must also provide an RPC_URL") + else: + raise ValueError("Must provide either NETWORK, or both CHAIN_ID and RPC_URL") wallet_provider = EthAccountWalletProvider( config=EthAccountWalletProviderConfig( diff --git a/python/create-onchain-agent/templates/chatbot/pyproject.toml.jinja b/python/create-onchain-agent/templates/chatbot/pyproject.toml.jinja index 88aa41d89..9b030ab17 100644 --- a/python/create-onchain-agent/templates/chatbot/pyproject.toml.jinja +++ b/python/create-onchain-agent/templates/chatbot/pyproject.toml.jinja @@ -11,7 +11,7 @@ python = "^3.10" python-dotenv = "^1.0.1" langchain-openai = "^0.2.4" langgraph = "^0.2.39" -coinbase-agentkit = "0.1.4" +coinbase-agentkit = "^0.1.4" coinbase-agentkit-langchain = "0.1.0" [tool.poetry.scripts] From 468ce9e0802ac2f45162d985b555725e24a1a7c6 Mon Sep 17 00:00:00 2001 From: CarsonRoscoe Date: Mon, 3 Mar 2025 15:32:54 -0500 Subject: [PATCH 08/10] chore: updated default to base-sepolia --- .../create-onchain-agent/templates/chatbot/chatbot.py.jinja | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja b/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja index f53b3b704..f602967f6 100644 --- a/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja +++ b/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja @@ -138,7 +138,11 @@ def initialize_agent(): elif chain_id: raise ValueError("When using chain_id, you must also provide an RPC_URL") else: - raise ValueError("Must provide either NETWORK, or both CHAIN_ID and RPC_URL") + print("No network configuration provided. Defaulting to Base Sepolia...") + network = "base-sepolia" + chain_id = NETWORK_ID_TO_CHAIN_ID[network] + chain = NETWORK_ID_TO_CHAIN[network] + rpc_url = chain["rpc_urls"]["default"]["http"][0] wallet_provider = EthAccountWalletProvider( config=EthAccountWalletProviderConfig( From 69c917e201abe08140f86c0adf9f85834043fdbd Mon Sep 17 00:00:00 2001 From: CarsonRoscoe Date: Mon, 3 Mar 2025 16:11:34 -0500 Subject: [PATCH 09/10] chore: improved network handling if only chain_id was received --- .../templates/chatbot/chatbot.py.jinja | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja b/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja index f602967f6..a361e6f6d 100644 --- a/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja +++ b/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja @@ -31,7 +31,7 @@ from coinbase_agentkit import ( from coinbase_agentkit_langchain import get_langchain_tools {% if _wallet_provider == "eth" %} from eth_account import Account -from coinbase_agentkit.network import NETWORK_ID_TO_CHAIN_ID, NETWORK_ID_TO_CHAIN +from coinbase_agentkit.network import NETWORK_ID_TO_CHAIN_ID, NETWORK_ID_TO_CHAIN, CHAIN_ID_TO_NETWORK_ID {% endif %} """ AgentKit Integration @@ -136,7 +136,13 @@ def initialize_agent(): chain = NETWORK_ID_TO_CHAIN[network] rpc_url = chain["rpc_urls"]["default"]["http"][0] elif chain_id: - raise ValueError("When using chain_id, you must also provide an RPC_URL") + # Try to find the network ID from the chain ID + network = CHAIN_ID_TO_NETWORK_ID.get(chain_id) + if network: + chain = NETWORK_ID_TO_CHAIN[network] + rpc_url = chain["rpc_urls"]["default"]["http"][0] + elif not rpc_url: + raise ValueError("When using chain_id, you must also provide an RPC_URL if the chain is not recognized") else: print("No network configuration provided. Defaulting to Base Sepolia...") network = "base-sepolia" From 5f239354117db789eb47d7d501060221524339ad Mon Sep 17 00:00:00 2001 From: CarsonRoscoe Date: Mon, 3 Mar 2025 16:13:34 -0500 Subject: [PATCH 10/10] chore: removed condition that will always be true --- python/create-onchain-agent/templates/chatbot/chatbot.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja b/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja index a361e6f6d..a415edac9 100644 --- a/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja +++ b/python/create-onchain-agent/templates/chatbot/chatbot.py.jinja @@ -141,7 +141,7 @@ def initialize_agent(): if network: chain = NETWORK_ID_TO_CHAIN[network] rpc_url = chain["rpc_urls"]["default"]["http"][0] - elif not rpc_url: + else: raise ValueError("When using chain_id, you must also provide an RPC_URL if the chain is not recognized") else: print("No network configuration provided. Defaulting to Base Sepolia...")