> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://www.getfoundry.sh/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

## `setNonceUnsafe`

### Signature

```solidity
function setNonceUnsafe(address account, uint64 newNonce) external;
```

### Description

Sets the nonce of `account` to `newNonce`. Unlike [`setNonce`](/reference/cheatcodes/set-nonce), which reverts when `newNonce` is lower than the current nonce, `setNonceUnsafe` accepts any value.

### Parameters

| Parameter  | Type      | Description                      |
|------------|-----------|----------------------------------|
| `account`  | `address` | The account to set the nonce for |
| `newNonce` | `uint64`  | The new nonce value              |

### Examples

```solidity [test/SetNonceUnsafe.t.sol]
// [!include ~/snippets/projects/nonces/test/SetNonceUnsafe.t.sol:set-nonce-unsafe]
```

The nonce of a contract decides the address of the next contract it creates with `CREATE`:

:::code-group
```solidity [test/SetNonceUnsafe.t.sol]
// [!include ~/snippets/projects/nonces/test/SetNonceUnsafe.t.sol:set-nonce-unsafe-create]
```

```solidity [src/Counter.sol]
// [!include ~/snippets/projects/nonces/src/Counter.sol]
```
:::

### Gotchas

:::warning
Lowering a nonce puts the account in a state the chain cannot reach. A contract whose nonce is lowered can compute a `CREATE` address it already deployed to, and that deployment fails.
:::

* The change is kept even if the call that made it reverts later, for example inside a `try` call that fails.

### Related Cheatcodes

* [`setNonce`](/reference/cheatcodes/set-nonce) - Sets the nonce of an account, only upward
* [`resetNonce`](/reference/cheatcodes/reset-nonce) - Resets the nonce of an account to its starting value
* [`getNonce`](/reference/cheatcodes/get-nonce) - Gets the nonce of an account
