'ERROR: brownie.exceptions.RPCConnectionError: Able to launch RPC client, but unable to connect
The ganache-cli is unable to connect to the mainnet fork, as a result of which I can't run brownie test --networks mainnet-fork
My test.py file looks like this:
from brownie import Lottery, accounts, network, config
def test_eth_amount():
account = accounts[0]
lottery = Lottery.deploy(
config["networks"][network.show_active()]["eth_usd_price_feed"],
{"from": account},
)
print(lottery)
assert lottery.getEntranceFee() > 18000000000000000
assert lottery.getEntranceFee() < 21000000000000000
And brownie-config file is:
dependencies:
# - <organization/repo>@<version>
- smartcontractkit/[email protected]
compiler:
solc:
remappings:
- '@chainlink=smartcontractkit/[email protected]'
# - '@chainlink=smartcontractkit/[email protected]'
# dotenv: .env
networks:
mainnet-fork:
eth_usd_price_feed: '0x5f4ec3df9cbd43714fe2740f5e3616155c5b8419'
But even then brownie can't connect to mainnet-fork!
The error message looks like this:
Launching 'ganache-cli.cmd --accounts 10 --fork https://eth-mainnet.alchemyapi.io/v2/w1kKuepExg3kpo_V4Dr4XHArsk3IWb0Y --mnemonic brownie --port 8545 --hardfork istanbul'...
Terminating local RPC client...
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\_pytest\main.py", line 269, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\_pytest\main.py", line 322, in _main
INTERNALERROR> config.hook.pytest_collection(session=session)
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\_pytest\main.py", line 333, in pytest_collection
INTERNALERROR> session.perform_collect()
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\_pytest\main.py", line 641, in perform_collect
INTERNALERROR> hook.pytest_collection_finish(session=self)
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\pluggy\_callers.py", line 55, in _multicall
INTERNALERROR> gen.send(outcome)
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\brownie\test\managers\runner.py", line 258, in pytest_collection_finish
INTERNALERROR> brownie.network.connect(CONFIG.argv["network"])
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\brownie\network\main.py", line 50, in connect
INTERNALERROR> rpc.launch(active["cmd"], **active["cmd_settings"])
INTERNALERROR> File "c:\users\hp\development\demos\brownie_simple_storage\venv\lib\site-packages\brownie\network\rpc\__init__.py", line 95, in launch
INTERNALERROR> raise RPCConnectionError(cmd, self.process, uri)
INTERNALERROR> brownie.exceptions.RPCConnectionError: Able to launch RPC client, but unable to connect.
INTERNALERROR>
INTERNALERROR> Command: ganache-cli
INTERNALERROR> URI: https://127.0.0.1:8545
INTERNALERROR> Exit Code: 15
My mainnet-fork network details also doesn't seem suspicious:
Network 'mainnet-fork' has been modified
└─mainnet-fork
├─id: mainnet-fork
├─cmd: ganache-cli
├─cmd_settings: {'accounts': 10, 'fork': 'https://eth-mainnet.alchemyapi.io/v2/w1kKuepExg3kpo_V4Dr4XHArsk3IWb0Y', 'mnemonic': 'brownie', 'port': 8545}
└─host: https://127.0.0.1
If the RPC doesn't connect to the proper network, It'll be difficult for me to continue with the course.
Solution 1:[1]
Open up Ganache and check which port you have at the start. Use the same port for the mainnet-fork. I used port: 7545
Solution 2:[2]
You just need to wait for the deploy transaction to finish:
from brownie import Lottery, accounts, network, config
def test_eth_amount():
account = accounts[0]
lottery = Lottery.deploy(
config["networks"][network.show_active()]["eth_usd_price_feed"],
{"from": account},
)
lottery.tx.wait(1)
print(lottery)
assert lottery.getEntranceFee() > 18000000000000000
assert lottery.getEntranceFee() < 21000000000000000
Solution 3:[3]
I had the same problem and was able to resolve it by manually creating a virtual python environment and then installing brownie with pip (instead of pipx):
- Install and activate a virtual python environment in your project. Instructions here.
- Install brownie using pip:
pip install eth-brownie
- Delete the mainnet-fork network in brownie.
- Re-create the mainnet-fork network in brownie.
Tests now run as expected.
Solution 4:[4]
i think that you should instant of creating a mainnet-fork with host=https://127.0.0.1:8545
do it with host=https://127.0.0.1:7545
Solution 5:[5]
It looks like you have created a network using https
for your localhost. Therefore, when you try to connect to it, it's refused and the RPCConnectionError
is thrown. You can check it by the log you sent:
INTERNALERROR> URI: https://127.0.0.1:8545
To solve it, you can try to delete your current mainnet-fork
with
brownie networks delete mainnet-fork
and recreate it using http
instead of https
in the host param, with
brownie networks add development mainnet-fork cmd=ganache-cli host=http://127.0.0.1 fork=...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Umut cuscus |
Solution 2 | Patrick Collins |
Solution 3 | |
Solution 4 | MOHAMED |
Solution 5 | Yuri Delgado |