> **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.

## `getDeployment`

### Signature

```solidity
function getDeployment(string calldata contractName) external view returns (address deployedAddress);
function getDeployment(string calldata contractName, uint64 chainId) external view returns (address deployedAddress);
```

### Description

Returns the address of the most recent deployment of `contractName` on `chainId`, read from the [broadcast files](/forge/broadcast-files) that `forge script --broadcast` writes. Without `chainId`, the current `block.chainid` is used.

`contractName` is matched against the `contractName` key of each transaction, such as `"Counter"`, not against the script name. A deployment is a `CREATE` or `CREATE2` transaction, and only transactions with a receipt count.

The cheatcode reads every timestamped run file under the [`broadcast`](/config/reference/project#broadcast) directory, from any script, and skips `-latest` files. It picks the newest run file on that chain that deploys the contract, then returns the deployment in the highest block. If several share that block, it returns the one the script sent first.

### Parameters

| Parameter      | Type     | Description                                             |
|----------------|----------|---------------------------------------------------------|
| `contractName` | `string` | The contract name, as recorded in the broadcast file    |
| `chainId`      | `uint64` | The chain to look up. Defaults to the current chain ID  |

### Returns

| Parameter         | Type      | Description                                    |
|-------------------|-----------|------------------------------------------------|
| `deployedAddress` | `address` | The address of the most recent deployment      |

### Examples

`script/Deploy.s.sol` deploys two `Counter` contracts and then calls `increment()` on the first one. Broadcasting it to a local Anvil node (chain ID 31337) wrote `broadcast/Deploy.s.sol/31337/run-<timestamp>.json`, which the tests below read.

:::code-group
```solidity [test/BroadcastLookup.t.sol]
// [!include ~/snippets/projects/broadcast_lookup/test/BroadcastLookup.t.sol:get-deployment]
```

```solidity [script/Deploy.s.sol]
// [!include ~/snippets/projects/broadcast_lookup/script/Deploy.s.sol]
```
:::

### Gotchas

* Reverts with `No broadcasts found` when no run file on that chain deploys `contractName`, and with `broadcast dir does not exist or is not a directory` when the `broadcast` directory is missing.
* The newest matching run file wins even if none of its transactions has a receipt. A later simulation without `--broadcast` writes `dry-run/run-<timestamp>.json` with the same transactions and no receipts, and `getDeployment` then reverts with `no deployment found for <contractName> on chain <chainId>`. The same happens after a broadcast that stopped before any receipt was saved.
* When a script deploys the same contract more than once, only one deployment is returned: the last one, or the first of several that land in the same block. Use [`getDeployments`](/reference/cheatcodes/get-deployments) for all of them, or [`getDeploymentByLabel`](/reference/cheatcodes/get-deployment-by-label) to pick one by its label.

### Related Cheatcodes

* [`getDeployments`](/reference/cheatcodes/get-deployments) - Returns every deployment of a contract
* [`getDeploymentByLabel`](/reference/cheatcodes/get-deployment-by-label) - Returns a deployment by its `vm.label`
* [`getBroadcast`](/reference/cheatcodes/get-broadcast) - Returns the most recent transaction of a given type

### See Also

* [Broadcast files](/forge/broadcast-files)
