4

I want to deploy a contract directly accessible in OpenZeppelin/[email protected] Brownie package without changes, namely ERC1967Proxy and other non-abstract contracts from Brownie console.

How can I import it in a Brownie script or console?

My brownie-config.yaml:

compiler:
  solc:
    version: 0.8.2
    remappings:
      - "@openzeppelin/contracts-upgradeable=~/.brownie/packages/OpenZeppelin/[email protected]/contracts"
      - "@openzeppelin-upgradeable=/home/etsvigun/.brownie/packages/OpenZeppelin/[email protected]"
      - "@openzeppelin=OpenZeppelin/[email protected]"
dependencies:
  - OpenZeppelin/[email protected]
  - OpenZeppelin/[email protected]

Imports work fine in Solidity code, from both remappings, like

import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

Trying to import contracts from packages just by names results in errors:

>>> from brownie import Proxy
  File "<console>", line 1, in <module>
ImportError: cannot import name 'Proxy' from 'brownie' (~/.local/pipx/venvs/eth-brownie/lib/python3.9/site-packages/brownie/__init__.py)

2 Answers 2

2

Found this pattern in a yearn repo, maybe this is what you are looking for ?

from brownie import project

Vault = project.load(
    Path.home() / ".brownie" / "packages" / config["dependencies"][0]
).Vault
4

You're close.

The dependencies section identifies where you want to download. You've correctly placed that part using github syntax. You want to download organization OpenZeppelin with repo openzeppelin-contracts.

Then, what you want to do is, "remap" your imports so that a keyword you've defined lines up with that package.

You're "remapping" "@openzeppelin/contracts-upgradeable to /home/etsvigun/.brownie/packages/OpenZeppelin/[email protected]/contracts. Instead, try this:

compiler:
  solc:
    version: 0.8.2
    remappings:
      - "@openzeppelin-upgradeable=OpenZeppelin/[email protected]"
      - "@openzeppelin=OpenZeppelin/[email protected]"
dependencies:
  - OpenZeppelin/[email protected]
  - OpenZeppelin/[email protected]

Don't use the entire file path when remapping.

2
  • 1
    The point of the question is "how do I import in a script" I.e. there's Escrow, which is not abstract and therefore can be instantiated. ``` brownie console ... Brownie environment is ready. >>> Escrow File "<console>", line 1, in <module> NameError: name 'Escrow' is not defined ``` Remapping above is just sidestepping the fact that Brownie quirk when you remap 2 packages with common prefix.
    – Utgarda
    Jul 29, 2021 at 14:04
  • I.e. these remappings work OK in contracts. I want to understand how to import contracts from packages in scripts. Will update the question.
    – Utgarda
    Jul 29, 2021 at 14:06

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.