Solmate (forge remappings)
Install solmate:
forge install rari-capital/solmate
Create an ERC20 contract:
pragma solidity ^0.8.17;
import "solmate/tokens/ERC20.sol";
contract Token is ERC20("name", "symbol", 18) {}
Build:
See what libraries have been installed:
$ forge remappings
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
solmate/=lib/solmate/src/
Here solmate
is remapped to lib/solmate/src/
.
OpenZeppelin Contracts (remappings.txt)
Some libraries, such as OpenZeppelin contracts, should be installed via npm:
mkdir node_modules && npm i @openzeppelin/contracts
We run mkdir
first because node modules can be install locally or globally. Reference:
In contract, import OpenZeppelin Ownable
:
import "@openzeppelin/contracts/access/Ownable.sol";
We have to create a remappings.txt
file for this import statement to make sense:
@openzeppelin/=node_modules/@openzeppelin
Update our contract:
pragma solidity ^0.8.17;
import "solmate/tokens/ERC20.sol";
contract Token is ERC20("name", "symbol", 18) {}
import "@openzeppelin/contracts/access/Ownable.sol";
contract TestOz is Ownable {}
Build it: