Using a generic SimpleStorage.sol contract and a deploy.py I'm able to create a contract on a Ganache local blockchain and access it during execution. On brownie console
is possible to do the same step by step. My problem rises as soon as the execution terminates or the console is closed as the contract I just deployed seems unreachable. If I reopen the console and I run SimpleStorage
the output given is an empty list (The contract I just deployed should be in the list but it's not).. so I try running Contract("contract_address")
But the result is the following error:
BrownieEnvironmentError: Functionality not available in local environment
Is there any workaround for this or am I thinking wrong and I can't actually access old deployed contracts on Ganache with brownie? If so can someone explain why?
Best Answer
After some tips I was able to solve so I'll post the simple solution I found.
So the problem was actually that I was deploying on a Development network and so brownie by default didn't save the deployments. So the solution was to create a new Ganache chain under Ethereum with the following command:
brownie networks add Ethereum ganache-local host=http://127.0.0.1:8545 chainid=5777
You can ensure the network has been correctly created by using
brownie networks list
which should output something like (truncated to Ethereum networks):├─Mainnet (Infura): mainnet ├─Ropsten (Infura): ropsten ├─Rinkeby (Infura): rinkeby ├─Goerli (Infura): goerli ├─Kovan (Infura): kovan └─ganache-local: ganache-local
After that you want brownie to use that new chain as default so I added the following lines into the brownie.config.yaml file:
This way you ensure that brownie actually keeps track of the deployments. Hopefully I can be of help to somebody. For further information take a look at this resource to understand better brownie’s behavior when it comes to the ganache chain: https://stackoverflow.com/a/69239681