Importing oz contracts with hardhat

I’ve been trying to pick up hardhat as I want to move away from remix, but I have a problem which I can’t seem to solve when trying to compile my contracts.

i try to import these contracts:

import “https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.1.0/contracts/GSN/Context.sol”;
import “https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.1.0/contracts/token/ERC20/IERC20.sol”;
import “https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.0.0/contracts/math/SafeMath.sol”;
import “https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.1.0/contracts/utils/Address.sol”;
import “https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.1.0/contracts/access/Ownable.sol”;

But it doesn’t work. I tried to change it to @openzeppelin/contracts/… but no luck. Am i missing something here?

Hardhat does not support importing files directly from github URLs like Remix does.

It will work with the change to @openzeppelin/contracts/... but you need to actually install Open Zeppelin first. Make sure you have npm installed and then run npm install @openzeppelin/contracts. It will put the files inside node_modules/ and generate a package.json file for you to keep track of which packages your project requires to run. You should put hardhat there too.

With that setup you will be able to easily recreate node_modules/ any time with all the necessary dependencies just by running npm install.