ethereumblockchainsmartcontractsganachebrownie

ValueError: Unknown URI - must be a path to an IPC socket, a websocket beginning with 'ws' or a URL beginning with 'http'


I am using Brownie and added a Ganache local network using the following command:

brownie networks add Development ganache-local host=HTTP://127.0.0.1:7545 cmd=ganache-cli

After compiling, I try to deploy the smart contracts with brownie run token.py --network ganache-local Then, I get the following error:

TokenProject is the active project.
  File "brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/run.py", line 45, in main
    network.connect(CONFIG.argv["network"])
  File "brownie/network/main.py", line 40, in connect
    web3.connect(host, active.get("timeout", 30))
  File "brownie/network/web3.py", line 68, in connect
    raise ValueError(
ValueError: Unknown URI - must be a path to an IPC socket, a websocket beginning with 'ws' or a URL beginning with 'http'

I did some digging and found this in the source code:

if self.provider is None:
    if uri.startswith("ws"):
        self.provider = WebsocketProvider(uri, {"close_timeout": timeout})
    elif uri.startswith("http"):
        self.provider = HTTPProvider(uri, {"timeout": timeout})
    else:
        raise ValueError(
                    "Unknown URI - must be a path to an IPC socket, a websocket "
                    "beginning with 'ws' or a URL beginning with 'http'"
                )

Does this mean I have to set a provider (like Alchemy) for my local network? Does that even make sense?


Solution

  • After 4 days of struggling, passing the network_id=5777 argument solved my problem. Apparently, brownie cannot recognize the local network created in the Ganache app without this argument.