---
description: Fetches and executes a transaction from a fork
---

## `transact`

### Signature

```solidity
function transact(bytes32 txHash) external;
function transact(uint256 forkId, bytes32 txHash) external;
```

### Description

In forking mode, fetches a transaction from the RPC provider and executes it on the current state. This allows you to replay historical transactions.

### Parameters

| Parameter | Type      | Description                                        |
|-----------|-----------|----------------------------------------------------|
| `txHash`  | `bytes32` | The transaction hash to fetch and execute          |
| `forkId`  | `uint256` | Fork to fetch from (optional, defaults to active)  |

### Examples

```solidity [test/Transact.t.sol]
function testTransact() public {
    // Fork at block 15596646
    vm.createSelectFork(MAINNET_RPC_URL, 15596646);

    // A transfer transaction in that block
    bytes32 txHash = 0xaba74f25a17cf0d95d1c6d0085d6c83fb8c5e773ffd2573b99a953256f989c89;

    address sender = 0xa98218cdc4f63aCe91ddDdd24F7A580FD383865b;
    address recipient = 0x0C124046Fa7202f98E4e251B50488e34416Fc306;
    uint256 transferAmount = 3936000000000000;

    uint256 recipientBalanceBefore = recipient.balance;
    uint256 senderBalanceBefore = sender.balance;

    // Execute the historical transaction
    vm.transact(txHash);

    // Verify the transfer happened
    assertEq(recipient.balance, recipientBalanceBefore + transferAmount);
    assertLt(sender.balance, senderBalanceBefore); // Less due to transfer + gas
}
```

### Related Cheatcodes

- [`rollFork`](/reference/cheatcodes/roll-fork) - Roll a fork to a block
- [`createFork`](/reference/cheatcodes/create-fork) - Create a fork
- [`selectFork`](/reference/cheatcodes/select-fork) - Select a fork
