Skip to content

Commit

Permalink
fix: use cached deployedBytecode where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Jul 3, 2024
1 parent 353440a commit 690da0c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions brownie/network/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,9 @@ def __init__(
self, address: str, owner: Optional[AccountsType] = None, tx: TransactionReceiptType = None
) -> None:
address = _resolve_address(address)
self.bytecode = web3.eth.get_code(address).hex()[2:]
self.bytecode = (
self._build.get("deployedBytecode", None) or web3.eth.get_code(address).hex()[2:]
)
if not self.bytecode:
raise ContractNotFound(f"No contract deployed at {address}")
self._owner = owner
Expand Down Expand Up @@ -948,7 +950,13 @@ def from_abi(
will be performed using this account.
"""
address = _resolve_address(address)
build = {"abi": abi, "address": address, "contractName": name, "type": "contract"}
build = {
"abi": abi,
"address": address,
"contractName": name,
"type": "contract",
"deployedBytecode": web3.eth.get_code(address).hex()[2:],
}

self = cls.__new__(cls)
_ContractBase.__init__(self, None, build, {}) # type: ignore
Expand Down

0 comments on commit 690da0c

Please sign in to comment.