# makePersistent

Description: makePersistent cheatcode documentation

Note: This document was authored using MDX

  Source: https://github.com/NomicFoundation/hardhat-website/tree/main/src/content/docs/docs/reference/cheatcodes/Forking/make-persistent.mdx

{/* This document contains content copied/adapted from the Foundry Book (MIT licensed). See LICENSE in the parent directory. */}

### Signature

```solidity
function makePersistent(address account) external;
function makePersistent(address account0, address account1) external;
function makePersistent(
  address account0,
  address account1,
  address account2
) external;
function makePersistent(address[] calldata accounts) external;
```

### Description

Each fork ([`createFork`](/docs/reference/cheatcodes/forking/create-fork)) has its own independent storage, which is also replaced when another fork is selected ([`selectFork`](/docs/reference/cheatcodes/forking/select-fork)).
By default, only the test contract account and the caller are persistent across forks, which means that changes to the state of the test contract (variables) are preserved when different forks are selected. This way data can be shared by storing it in the contract's variables.

However, with this cheatcode, it is possible to mark the specified accounts as persistent, which means that their state is available regardless of which fork is currently active.

### Examples

Mark a new contract as persistent

```solidity
contract SimpleStorageContract {
  string public value;

  function set(uint256 _value) public {
    value = _value;
  }
}

function testMarkPersistent() public {
  // by default the `sender` and the contract itself are persistent
  assert(cheats.isPersistent(msg.sender));
  assert(cheats.isPersistent(address(this)));

  // select a specific fork
  cheats.selectFork(mainnetFork);

  // create a new contract that's stored in the `mainnetFork` storage
  SimpleStorageContract simple = new SimpleStorageContract();

  // `simple` is not marked as persistent
  assert(!cheats.isPersistent(address(simple)));

  // contract can be used
  uint256 expectedValue = 99;
  simple.set(expectedValue);
  assertEq(simple.value(), expectedValue);

  // mark as persistent
  cheats.makePersistent(address(simple));

  // select a different fork
  cheats.selectFork(optimismFork);

  // ensure contract is still persistent
  assert(cheats.isPersistent(address(simple)));

  // value is set as expected
  assertEq(simple.value(), expectedValue);
}
```

### SEE ALSO

- [isPersistent](/docs/reference/cheatcodes/forking/is-persistent)
- [revokePersistent](/docs/reference/cheatcodes/forking/revoke-persistent)
- [createFork](/docs/reference/cheatcodes/forking/create-fork)
- [selectFork](/docs/reference/cheatcodes/forking/select-fork)
