How to make VSC Solidity lint recognize your @chainlink and @openzeppelin libraries
The following solution is written for Windows, but Mac should be very similar with minor changes in the path. Please keep in mind that lint is not necessary for the code to work, this is just for lint to recognize the libraries.
- Please check if you have the desired packages already installed with
brownie pm list
- If the package is not listed you will need to install it first. Here is an example for OpenZeppelin
brownie pm install OpenZeppelin/openzeppelin-contracts@3.0.0
- Regardless of whether you installed the package under a virtual environment, Brownie will store the package as follows.
C:\Users\Username\.brownie\packages ...
or more specific inC:\Users\Zarathustra\.brownie\packages\OpenZeppelin\openzeppelin-contracts@3.0.0
or here is the path for chainlinkC:\Users\Zarathustra\.brownie\packages\smartcontractkit\chainlink-brownie-contracts@0.3.0
- Copy the path, for Windows remove the drive letter and revert the backslashes into (forward) slashes, the Chainlink path should now look like this:
/Users/Zarathustra/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@0.3.0
- In Visual Studio Code press
Ctrl + ,
and type into the search boxsolidity.remap
- Click the small link (see screenshot) and open the settings file
- Adapt the following lines to your needs and add them to the settings file.
,
"solidity.remappings": [
"@chainlink/=/Users/UserName/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@0.3.0",
],
The logic is as follows: Whenever VSC Solidity encounters “@chainlink/” it will search for the library in the path which is written after the equal sign. So @chainlink/contracts will look at the path and add /contracts etc.
You can add more solidity.remappings into the data structure separated by commas and enclosed in double quotation marks.
Here just for comparison my settings.json file (do not blindly copy it)
{
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"python.pythonPath": "C:\\Users\\UserName\\pythonversions\\python3.9.1\\python.exe",
"python.languageServer": "Pylance",
"python.venvFolders": [
"C:\\Users\\UserName\\pythonprojects",
"C:\\Users\\UserName\\blockchainProjects"
],
"workbench.editorAssociations": {
"*.ipynb": "jupyter.notebook.ipynb"
},
"python.defaultInterpreterPath": "C:\\Users\\UserName\\pythonversions\\python3.9.1\\python.exe",
"solidity.packageDefaultDependenciesDirectory": "node_modules",
"solidity.compileUsingRemoteVersion": "latest",
"solidity.remappings": [
"@chainlink/=/Users/UserName/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@0.3.0",
],
"editor.formatOnSave": true,
"python.formatting.provider": "black",
"editor.bracketPairColorization.enabled": true,
"python.venvPath": "~/.venv"
}
The changes should take effect immediately.