question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Can't use brownie console with anvil to deploy contracts

See original GitHub issue

Environment information

  • brownie Version: 1.19.0
  • solc Version: 0.8.10
  • Python Version: 3.9.7
  • OS: osx

What was wrong?

Please include information like: Can’t deploy contracts using the accounts object with anvil as I get a “to” key error

  • what command you ran The command I ran was
brownie console --network anvil

The error in the console and the code that lead to it.

>>> from brownie import *
>>> accounts[0].deploy(MockCurveOracle)
Transaction sent: 0xedbbeef98ae3fcad52be3bd2244d62c6cfba48ada5c39b18b365453bdf1d6a09
  File "<console>", line 1, in <module>
  File "brownie/network/account.py", line 510, in deploy
    receipt, exc = self._make_transaction(
  File "brownie/network/account.py", line 759, in _make_transaction
    receipt = TransactionReceipt(
  File "brownie/network/transaction.py", line 199, in __init__
    self._set_from_tx(tx)
  File "brownie/network/transaction.py", line 549, in _set_from_tx
    self.receiver = EthAddress(tx["to"]) if tx["to"] else None
  File "web3/datastructures.py", line 51, in __getitem__
    return self.__dict__[key]  # type: ignore
KeyError: 'to'

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
WyseNynjacommented, Jun 4, 2022

I’m pretty sure there’s no “detection” of the underlying rpc. It just assumes it’s ganache if it’s connecting to an already running rpc because that’s all that used to exist. Adding something to check the client would be a good idea.

1reaction
WyseNynjacommented, Jun 2, 2022

For the first one, I’m guessing anvil doesn’t return anything for “to” when it’s ZERO_ADDRESS. That should be easy to handle in brownie, but at first glance it seems like an anvil bug.

For your second error, anvil is strict about wanting hex encoded integers for seemingly everything. For the “chain.sleep” and similar chain commands I do this encoding for the user. Maybe we need a middleware to make it automatic for more commands. Or maybe anvil could be less strict in its parsing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Brownie Documentation
Anvil may be used as an alternative to Ganache within Brownie. To use Anvil with Brownie, you must first follow their steps to...
Read more >
eth-brownie/community - Gitter
Hi guys. I'm having some issues getting updates to a contract to get compiled. I've changed a couple comments in file contracts/GTC.sol, and...
Read more >
brownie/CHANGELOG.md at master - GitHub
A Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine. - brownie/CHANGELOG.md at ...
Read more >
I'm trying to deploy a smart contract on Goerli, but receiving an ...
I've had the same issue before. It's like due to the Fundme was not loaded. The workaround was to use brownie console instead...
Read more >
Brownie: Python for Smart Contracts Targeting The EVM
Once installed, you will never have to activate a virtual environment prior to using Brownie. To install pipx : python3 -m pip install...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found