Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to run "brownie run .\scripts\deploy.py --network rinkeby" but getting a ValueError

Hey guys I am trying to deploy my project on the rinkeby chain using infura, but I am getting a ValueError Here is my trackback:

INFO: Could not find files for the given pattern(s).
Brownie v1.17.1 - Python development framework for Ethereum

  File "c:\users\allow\appdata\local\programs\python\python39\lib\site-packages\brownie\_cli\__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "c:\users\allow\appdata\local\programs\python\python39\lib\site-packages\brownie\_cli\run.py", line 44, in main
    network.connect(CONFIG.argv["network"])
  File "c:\users\allow\appdata\local\programs\python\python39\lib\site-packages\brownie\network\main.py", line 40, in connect
    web3.connect(host, active.get("timeout", 30))
  File "c:\users\allow\appdata\local\programs\python\python39\lib\site-packages\brownie\network\web3.py", line 52, in connect
    uri = _expand_environment_vars(uri)
  File "c:\users\allow\appdata\local\programs\python\python39\lib\site-packages\brownie\network\web3.py", line 183, in _expand_environment_vars
    raise ValueError(f"Unable to expand environment variable in host setting: '{uri}'")
ValueError: Unable to expand environment variable in host setting: 'https://rinkeby.infura.io/v3/$WEB3_INFURA_PROJECT_ID'

Here is my deploy.py code

from brownie import accounts, config, SimpleStorage, network
import os

def deploy_simple_storage():
    account = get_account()
    simple_storage = SimpleStorage.deploy({"from": account})
    stored_value = simple_storage.retrieve()
    print(stored_value)
    transaction = simple_storage.store(15, {"from": account})
    transaction.wait(1)
    updated_stored_value = simple_storage.retrieve()
    print(updated_stored_value)


def get_account():
    if network.show_active() == "development":
        return accounts[0]
    else:
        return accounts.add(config["wallets"]["from_key"])


def main():
    deploy_simple_storage()

I have a really little experience in coding. I think the problem is related to .env, but I don't know what I should now. FYI I am using windows n follow this course https://www.youtube.com/watch?v=M576WGiDBdQ stuck at 4:48:00

like image 278
3lii06 Avatar asked Nov 07 '25 01:11

3lii06


2 Answers

it appears your env variables are not set correctly, and it looks like in this case it's your WEB3_INFURA_PROJECT_ID.

You can fix it by setting the variable in your .env file and adding dotenv: .env to your brownie-config.yaml.

brownie-config.yaml:

dotenv: .env .env:

export WEB3_INFURA_PROJECT_ID=YOUR_PROJECT_ID_HERE Remember to save these files.

Additionally, you should be on at least brownie version v1.14.6. You can find out what version you're on with:

brownie --version

like image 94
Renzo Tello Avatar answered Nov 09 '25 19:11

Renzo Tello


I had the same issue (Mac OS) and I looked at another YouTube around Brownie Deployment and noticed that "network" needs to be defined at import.

This line of code above the from brownie import did the trick in my deploy.py:

import brownie.network as network
like image 42
Oscar Amos Avatar answered Nov 09 '25 17:11

Oscar Amos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!