# Remappings

{% embed url="https://youtu.be/7DK75j8csTA" %}

## Solmate (forge remappings)

Install solmate:

```bash
forge install rari-capital/solmate
```

Create an ERC20 contract:

```solidity
pragma solidity ^0.8.17;

import "solmate/tokens/ERC20.sol";

contract Token is ERC20("name", "symbol", 18) {}
```

Build:

```bash
forge build
```

See what libraries have been installed:

```bash
$ 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:

```bash
mkdir node_modules && npm i @openzeppelin/contracts
```

We run `mkdir` first because node modules can be install locally or globally. Reference:

{% embed url="https://stackoverflow.com/questions/14032160/npm-install-module-in-current-directory" %}

In contract, import OpenZeppelin `Ownable`:

```solidity
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:

```solidity
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:

```bash
forge build
```

<figure><img src="https://3988450783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWVjG_njKgBtvmnKaJh%2Fuploads%2FZAVvdr5ufvs3BwrkvBZ8%2Fimage.png?alt=media&#x26;token=644bce6c-1264-4776-af67-dbb271327335" alt=""><figcaption><p>Build succeeded</p></figcaption></figure>
