full-blockchain-solidity-course-py icon indicating copy to clipboard operation
full-blockchain-solidity-course-py copied to clipboard

KeyError : 'wallets'

Open RevanthGundala opened this issue 3 years ago • 2 comments

When I try to run my code it is giving me a KeyError for 'wallets'

code for deploy.py:

from brownie import accounts, config, SimpleStorage, network #helps us get the address and private key #import os - METHOD 1 FOR NON_LOCAL blockchain

def deploy_simple_storage(): account = get_account() #brownie creates 10 accounts when you hit run - only works with ganache simple_storage = SimpleStorage.deploy({"from": account}) #deploys contract stored_value = simple_storage.retrieve() #view function, so no need to add "from account" print(stored_value) transaction = simple_storage.store(15, {"from": account}) transaction.wait(1) #wait for how many blockchains updated_stored_value = simple_storage.retrieve() print(updated_stored_value)

def get_account(): if network.show_active() == "development": #checks if we are using ganache return accounts[0] else: return accounts.add(config["wallets"]["from_key"])

def main(): #defining function deploy_simple_storage()

code for brownie-config.yaml:

dotenv: .env wallets: from_key: ${PRIVATE_KEY}

Any help would be appreciated.

RevanthGundala avatar Feb 19 '22 18:02 RevanthGundala

It would be useful to post the error.

Did you indent from_key: ${PRIVATE_KEY} in your brownie-config.yaml file?

Check your .env file as well to make sure it is named as PRIVATE_KEY.

leebut avatar Feb 20 '22 13:02 leebut

When I try to run my code it is giving me a KeyError for 'wallets'

code for deploy.py:

from brownie import accounts, config, SimpleStorage, network #helps us get the address and private key #import os - METHOD 1 FOR NON_LOCAL blockchain

def deploy_simple_storage(): account = get_account() #brownie creates 10 accounts when you hit run - only works with ganache simple_storage = SimpleStorage.deploy({"from": account}) #deploys contract stored_value = simple_storage.retrieve() #view function, so no need to add "from account" print(stored_value) transaction = simple_storage.store(15, {"from": account}) transaction.wait(1) #wait for how many blockchains updated_stored_value = simple_storage.retrieve() print(updated_stored_value)

def get_account(): if network.show_active() == "development": #checks if we are using ganache return accounts[0] else: return accounts.add(config["wallets"]["from_key"])

def main(): #defining function deploy_simple_storage()

code for brownie-config.yaml:

dotenv: .env wallets: from_key: ${PRIVATE_KEY}

Any help would be appreciated.

Please check if your .env and brownie-config.yaml file is in the root directory of the project. I have that same issue and I realized that I put my files in the scripts directory, I change to the root directory and I solved that issue.

bananlabs avatar Mar 28 '22 23:03 bananlabs