Solidity Foundry Import Forge – How to Install Multiple Versions of a Dependency in Foundry

forgefoundryimportsolidity

In hardhat multiple versions of a dependency can be installed as follows in the package.json(assuming yarn is being used):

"@openzeppelin/contracts": "^4.3.2",
"openzeppelin-contracts-solc-0.7": "yarn:@openzeppelin/[email protected]",

If you want to use v4.3.2 then you can import "@openzeppelin/contracts/..." and similarly if you want to use v3.4.2-solc-0.7 then you can import "openzeppelin-contracts-solc-0.7/..."

How can this be achieved in foundry?

Best Answer

If you want to install say the 2 versions of @openzeppelin/contracts stated in the question, they can be installed as follows:

# notice show openzeppelin-contracts-solc-0.7= is prepended to the dependency
# this will name the dependency "openzeppelin-contracts-solc-0.7" instead of the default name "openzeppelin-contracts"
forge install openzeppelin-contracts-solc-0.7=openzeppelin/[email protected]

# now install the latest version of openzeppelin-contracts as follows
forge install openzeppelin/openzeppelin-contracts