Arslan Amir
Arslan Amir

Reputation: 39

Can't import chainlink contracts

I've looked though all the other questions on this topic and no answers seem to work, I have run npm i @chainlink/contracts. But still I can not import these contracts. It works perfectly on remix but in vscode with hardhat, nothing seems to fix it.

import "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol";

Upvotes: 1

Views: 2416

Answers (4)

CyberPil0t
CyberPil0t

Reputation: 1

I'm having the same issue. I changed from Solidity by Juan Blanco - to Solidity by Nomic Foundation.

Tried installing using NPM and Yarn, the IDE stopped underlining the import. But I still get a compilation error.

    Error (6275): Source "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol" not found: File not found. Searched the following locations: "/Users/christianreyes/Documents/GitHub/Cyfrin_Audit_Course".
ParserError: Source "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol" not found: File not found. Searched the following locations: "/Users/christianreyes/Documents/GitHub/Cyfrin_Audit_Course".

I am of course working w/ the aggregator not VRF but this issue seems to be the same anyways.

but I have verified the path 10xs.

I know I can just create the interface and import that (as a quick solution) But i don't like when things just don't work and I can't figure out why.

Upvotes: 0

yahdielo
yahdielo

Reputation: 1

You are missing something in your import path.

you have:

import "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol";

it should be:

import "@chainlink/contracts/src/v0.8/vrf/VRFConsumerBaseV2.sol";

this should fix the problem.

** note: make sure you install the chainlink packages via:

npm install @chainlink/contracts --save

Upvotes: 0

Jason Whittaker
Jason Whittaker

Reputation: 25

If you look at the Github repos for Chainlink/contracts, the path has changed slightly. It's now - import "@chainlink/contracts/src/v0.8/vrf/VRFConsumerBaseV2.sol";

Upvotes: 1

Aindriú
Aindriú

Reputation: 3740

I had the same problem, red lines under the imports.

The solution was to change the VSCode Extension - Solidity by Juan Blanco - to Solidity by Nomic Foundation

Solidity by Nomic Foundation enter image description here

https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity

Before

enter image description here

After enter image description here

Upvotes: 2

Related Questions