KeyError: 'mainnet-fork' when using brownie console --network mainnet-fork

Viewed 820

I'm following Solidity tutorial from FreeCodeCamp and I'm getting an error when trying to deploy to mainnet-fork using brownie and infura. If I deploy to Kovan, everything works just fine. It's the mainnet-fork which is not working.

I have setup .env with:

export PRIVATE_KEY = 0xsomethingsomething
export WEB3_INFURA_PROJECT_ID = 2bsomethingsomething
export ETHERSCAN_TOKEN = QBsometoken

and brownie-config.yaml includes

dependencies:
  - aave/protocol-v2@1.0.1
compiler:
  solc:
    remappings:
      - '@aave=aave/protocol-v2@1.0.1'
dotenv: .env    
networks:
  default: mainnet-fork
  mainnet-fork:
    weth_token: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
    lending_pool_addresses_provider: '0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5'
    dai_eth_price_feed: '0x773616E4d11A78F511299002da57A0a94577F1f4'
    dai_token: '0x6b175474e89094c44da98b954eedeac495271d0f'
wallets:
  from_key: ${PRIVATE_KEY}

when executing

brownie console --network mainnet-fork

I get following output:

Brownie v1.17.1 - Python development framework for Ethereum

AaveBrowniePyFreecodeProject is the active project.
  File "brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/console.py", line 58, in main
    network.connect(CONFIG.argv["network"])
  File "brownie/network/main.py", line 31, in connect
    active = CONFIG.set_active_network(network)
  File "brownie/_config.py", line 76, in set_active_network
    network = self.networks[id_].copy()
KeyError: 'mainnet-fork'
2 Answers

Seems like problem was at forking mainnet. I've tried same code on another computer I have and everything worked fine. This time mainnet was forked properly and code runs without any errors.

SOLUTION: delete ~/.brownie folder and fork mainnet again

I think the error is in your brownie config file. The networks: branch should look something like this:

networks:
  mainnet-fork:
    eth_usd_price_feed: '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419'

i.e there should be a network name in between networks and eth-usd-price-feed

Related