3lii06
3lii06

Reputation: 55

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

Upvotes: 4

Views: 946

Answers (4)

Oscar Amos
Oscar Amos

Reputation: 11

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

Upvotes: 1

JJco
JJco

Reputation: 1

I followed the same course and was stuck too. I just put my infura project ID as a environment variable on my system(windows10) not on the .env file. https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html

Upvotes: 0

iconic Oreo
iconic Oreo

Reputation: 19

I've had this error for days and have seen it posted alot online. I was simply 1 directory up from where I needed to be - I followed the Patrick Collins tutorial very closey with the addition of setting up a virtual env, so maybe others are simply having the same problem I had.

I was originally in a directory "\demos\web3 brownie" which contained a folder called "brownie" and my python virtual env files.

The script is now running when I'm in directory "\demos\web3 brownie\brownie" which contains the brownie build, script, contract directories

Upvotes: 0

Renzo Tello
Renzo Tello

Reputation: 66

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

Upvotes: 3

Related Questions