0

This is how I used to interact with deployed contracts when using truffle console

let contract = await Whitelist.deployed()
contract.getWhitelist()

However, I am now using a brownie console and this was the only way I was able to do the same.

NOTE: I freshly re-deployed the contract with brownie run deploy_contracts.py

>>> contract = Whitelist.at("0x7CB3e6C814ddC99469B7e24271c90b9Aef610648")
>>> contract.getWhitelist()

Here it's obviously time-consuming to always have to search and paste an address inside a function.

Is there maybe an equivalent of deployed() command in the Brownie console that I am missing?

0

2 Answers 2

2

You can get a reference to your latest deployed contract with:

contract = Whitelist[-1]
2
  • Yeah, that might be it! I was trying to do it with Whitelist[0] but that didn't seem to work. I try to test it today and return back to accept the answer if it worked.
    – Sky
    Mar 17, 2022 at 7:36
  • Hmm, it doesn't seem to work. Any other ideas?
    – Sky
    May 26, 2022 at 21:03
0

Usually, when you fire brownie console, you are firing it from the development network. Therefore, you will be unable to read deployed contract without changing the network first. Ensure you set the network to the designated testnet where your contract is deployed. You can do this as follow in the terminal:

  1. In the terminal, write "brownie console --network rinkeby"
  2. In my case the contract is simple storage so I wrote on the console: from brownie import accounts, config, Storage as St, network
  3. Then I retrieve the information as simple as simple_storage = St[-1].retrieve()
  4. You can do this print line as a check: print(f"Address of this contract is {simple_storage}")

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.