Help With Brownie and Infura Environment Variables (Will send a $tip for the help)

Hello, I’m a novice to coding in general and I’m stuck with a problem while trying to run a script using Brownie in Studio Visual Code. I think my problem is with the environment variables in brownie(I’m probably doing something wrong in the brownie-config.yaml file) while trying to use the Kovan test network. I’ve used Infura to create a Project ID, and I have metamask for a private key. When I run “brownie run scripts/deploy.py --network kovan” I receive this error “raise ValueError(f"Unable to expand environment variable in host setting: ‘{uri}’”)
ValueError: Unable to expand environment variable in host setting: ‘https://kovan.infura.io/v3/$WEB3_INFURA_PROJECT_ID’’ Do you have any suggestions? Thank you. This may be a simple solution for someone, and I’ll send a tip to someone that’s willing to help guide me through a few steps. Thanks again.

1 Like

Hey @Brian_Lee_Victory, and welcome to the Infura community! After doing some digging and carefully looking at your error messages, I don’t think this is a Brownie issue as much as a Python issue.

You may want to look into os.path.expandvars(path) on this page. This will alow you to expand the environment variables at whatever path you put into it, which would be the Kovan URL you have mentioned.

Let me know if that works! If not, we’ll keep digging! :slight_smile:

1 Like

Hi @Leiya_Kenney, thank you so much for the reply and info. I’ve been reading over that article as I try to gain an understanding of environment variables since I’m new to coding in general. At the moment I"m receiving this Attribute error from running a script in Brownie, so I’ll just have to keep digging:

$ brownie run scripts/deploy.py --network kovan
INFO: Could not find files for the given pattern(s).
Brownie v1.14.3 - Python development framework for Ethereum

NewFolderProject is the active project.
  File "c:\users\brian, line line, in in
    return_value, frame = run(
  File "c:\users\brian, line line, in in
    raise AttributeError(f"Module '{name}' has no method '{method_name}'")
AttributeError: Module 'Users.Brian Lee.Python39.brownie.New folder.scripts.deploy' has no method 'main```

So that INFO error at the top is telling you that python.exe is not in the path that you’re trying to run - I’d check into fixing that first! When in doubt, follow the error messages :slight_smile:

1 Like

Hi Brian,
Just came across this. It looks like your first issue can be solved with this: https://ethereum.stackexchange.com/questions/102807/eth-brownie-unable-to-expand-environment-variable-in-host-setting/102808#102808

And your 2nd issue can be solved by adding a function named main in your deploy.py script.

Hope it helps.

1 Like

I am also getting similar issue. Are you able to resolve it? If yes then can you post the solution that you have found.

1 Like

Hi @Bhushan_P, and welcome to the Infura community! What error message are you seeing?

Hi @Brian_Lee_Victory,

Did you manage to solve the first issue?

I’m getting the same error message.

I created an .env file in my folder and added my private key in there and also the infura project id.

Also I tried to add the private key and the infura project id to a bash file when a terminal opens.

It seems like a tutorial to use the.env file, to set the infura project id and to set the private key hidden and to get these from inside Brownie would help.

This is essential to deploy a script on the Kovan network.

Has anyone figured this part out?

I have looked at most links here with the solution. But until now I have not been able to deploy on kovan.

@PatrickAlphaC
I’m following your youtube workshop on Brownie. The 1 hour one and also the 16 hours one! Lol.

Keep up the great work!!!

But this little environment thing - I’m using a Mac - is in my way to achieve your greatness with Brownie!!!

I had the same issue and it turned out the environment variable WEB3_INFURA_PROJECT_ID had a space at the end. Removing it fixed the problem.
Hope that helps.

Hi @Runy_Calmera

Could you please let us know if you managed to resolve the issue you’re encountering?