Is this kind of import valid for Remix only?
Short answer: yes, AFAIK currently pretty much only Remix supports URLs in imports in such a way that you can just paste one and have it just work.
Long answer: It could work but with most tools it won’t. The Solidity compiler provides two mechanisms that can be used to make it work with any tool:
- You can clone the repo and use import remapping to tell the compiler that the content of
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.1.0/contracts/ can be found in a local directory on your compuer.
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.1.0/contracts/access/Ownable.sol" and they can download the file and return the content in response.
Remix uses the callback but it’s pretty much an exception among the tools I know of.
The support for remappings is easier to add and some tools do support them (Brownie, dapp-tools), some don’t (Truffle, Hardhat). vscode-solidity extension does not support them yet but it has been requested (https://github.com/juanfranblanco/vscode-solidity/issues/183) and Juan said recently that he’s going to work on adding them.
Right answer: Remix supports importing directly from npm packages. Just change the import to
@openzeppelin/contracts/access/Ownable.sol and it will work in both Remix and vscode-solidity (with vscode extension you of course have to install the package using npm).