---
description: Copies storage from one contract to another
---

## `copyStorage`

### Signature

```solidity
function copyStorage(address from, address to) external;
```

### Description

Copies all storage from one contract address to another.

### Parameters

| Parameter | Type      | Description                        |
|-----------|-----------|------------------------------------|
| `from`    | `address` | The source address to copy from    |
| `to`      | `address` | The destination address to copy to |

### Examples

:::code-group

```solidity [test/CopyStorage.t.sol]
function testCopyStorage() public {
    Counter original = new Counter();
    original.setCount(1000);
    
    Counter copy = new Counter();
    copy.setCount(1);
    assertEq(copy.count(), 1);

    vm.copyStorage(address(original), address(copy));
    // Storage is copied from original to copy
    assertEq(copy.count(), 1000);
}
```

```solidity [src/Counter.sol]
contract Counter {
    uint256 public count;

    function setCount(uint256 x) public {
        count = x;
    }
}
```

:::

### Gotchas

:::warning
This cheatcode is not allowed if the target address has arbitrary storage set via [`setArbitraryStorage`](/reference/cheatcodes/set-arbitrary-storage).
:::

### Related Cheatcodes

- [`load`](/reference/cheatcodes/load) - Loads a single storage slot
- [`store`](/reference/cheatcodes/store) - Stores a value to a single storage slot
- [`setArbitraryStorage`](/reference/cheatcodes/set-arbitrary-storage) - Makes storage fully symbolic
