# etch

Description: etch cheatcode documentation

Note: This document was authored using MDX

  Source: https://github.com/NomicFoundation/hardhat-website/tree/main/src/content/docs/docs/reference/cheatcodes/Environment/etch.mdx

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

### Signature

```solidity
function etch(address who, bytes calldata code) external;
```

### Description

Sets the bytecode of an address `who` to `code`.

### Examples

```solidity
bytes memory code = address(awesomeContract).code;
address targetAddr = makeAddr("target");
vm.etch(targetAddr, code);
log_bytes(address(targetAddr).code); // 0x6080604052348015610010...
```

#### Using `vm.etch` for enabling custom precompiles

Some chains, like Blast or Arbitrum, run with custom precompiles. If you are encountering reverts due to not available precompile, you can use `vm.etch` cheatcode to inject mock of the missing precompile to the address it is expected to appear at.

```solidity
 // [!include ~/snippets/projects/cheatcodes/test/BlastMock.t.sol::all]
```

<div class="warning">

Injecting mocks of precompiles might be tricky as such mocks will not fully emulate the actual precompile behavior on-chain.

Mock in the case above will not cause the actual yield to be accrued if any yield mode is configured.

</div>

### SEE ALSO

Forge Standard Library

- [`deployCode`](https://getfoundry.sh/reference/forge-std/deployCode)
- [`deployCodeTo`](https://getfoundry.sh/reference/forge-std/deployCodeTo)
