3

I'm working with a Solidity using Brownie Framework running on WSL2 Ubuntu 20.04 on Windows 10 host machine.

And I have to import chainlink dependecies to my project, so I have the following importors

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol"; 

To get them work properly I added the folling code to brownie-config.yaml

dependencies:
  # - <organization/repo>@<version>
  - smartcontractkit/chainlink-brownie-contracts@1.1.1
compiler:
  solc:
    remappings:
      - "@chainlink=smartcontractkit/chainlink-brownie-contracts@1.1.1"

So running brownie compile, the compiler works just fine, however visual studio code complains about the imports

Vscode error

Additional Info: I'm using the romote compiler version, and if I change it to "localNodeModule" Vscode stops complaining about the import but it starts to complain about solidity version:

Solidity error

And I not able to compile the project anymore.

I read some other post like this one: VScode Solidity extension - not finding openzepplin imports with similar problems, but unfornatelly the problems still unresolve.

Cromewar
  • 155
  • 9
  • You need to configure vscode solidity to be able to find your chainlink contract. You can [point it at your `node_modules`](https://github.com/juanfranblanco/vscode-solidity#project-structure) (if you install chainlink via npm) or [try the freshly added support for remappings to make it use packages installed by Brownie](https://github.com/juanfranblanco/vscode-solidity/issues/183#issuecomment-929197969). – cameel Oct 03 '21 at 02:14
  • Thanks for the help – Cromewar Nov 09 '21 at 14:45

3 Answers3

3

Brownie stores library contract data (Chainlink, OpenZeppelin, other dependencies) inside of Users/$yourUsername/.brownie/packages. That's on Mac at least. If you're on Windows, look for a .brownie directory.

To point the Ethereum VS Code extension to these files, you can add a Solidity remapping. This can be done by adding the following:

"solidity.remappings": [
    "@openzeppelin/=/Users/rafi/.brownie/packages/OpenZeppelin/openzeppelin-contracts@4.4.0"
  ]

to your settings.json file in VS Code. After restarting VS Code, the warning/error should disappear!

Check out the readme for the Ethereum VS Code extension for more info.

Rafi
  • 31
  • 4
0

In my case even the remapping in the brownie-config.yaml did not work, but specifying the local path directly in the import did work. Not sure why (would be interested to figure it out).

Not working:

// in contract
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
// in brownie-config.yaml
dependencies:
  - smartcontractkit/chainlink-brownie-contracts@1.1.1
compiler:
  solc:
    remappings:
      - '@chainlink=/Users/<your-user>/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@1.1.1'

Working:

// in contract
import "/Users/filippomassarelli/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@1.1.1/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
0

I solved it by doing: npm install @chainlink/contracts --save

and in the yaml file doing:enter image description here