etch
Signature
Section titled “Signature”function etch(address who, bytes calldata code) external;Description
Section titled “Description”Sets the bytecode of an address who to code.
Examples
Section titled “Examples”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
Section titled “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.
// [!include ~/snippets/projects/cheatcodes/test/BlastMock.t.sol::all]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.
SEE ALSO
Section titled “SEE ALSO”Forge Standard Library