# Forge

### Inspect

{% code title="List out all the methods and function selectors in a contract" %}

```bash
forge inspect <CONTRACT_NAME> methods
```

{% endcode %}

{% code title="Inspect contract and view storage layout" %}

```bash
forge inspect <CONTRACT_NAME> storageLayout
```

{% endcode %}

{% code title="Create .gas-snapshot for all tests" %}

```bash
forge snapshot
```

{% endcode %}

{% hint style="info" %}
If you see the error `EvmError: NotActivated` when trying to deploy contracts using `forge` it may be that you need to explicitly set the `--evm-version` when running the forge command.

The evm version can also be set in the `foundry.toml` file:

```toml
[profile.default]
evm_version = "cancun"
```

{% endhint %}

### Contract Verification

If automatic contract verification fails during deployment it can be performed manually using forge.

{% code overflow="wrap" %}

```bash
forge verify-contract <CONTRACT_ADDRESS> ./src/<CONTRACT>.sol:<CONTRACT_NAME> --chain-id <CHAIN_ID> --watch --etherscan-api-key <ETHERSCAN_API_KEY>
```

{% endcode %}

* `--watch` leaves the terminal waiting for a status confirmation reply.
* If constructor arguments are required they can be encoded using `cast` e.g for a constructor requiring a single address:

```solidity
cast abi-encode "constructor(address)" <ADDRESS_TO_PASS_INTO_CONSTRUCTOR>
```

* Then use that `cast` output  to add `--constructor-args` to the end of the `forge verify-contract` command.

{% hint style="info" %}
For Ethereum L1 or L1 testnets use the Etherscan API key: <https://etherscan.io/myapikey>

For L2s (e.g. Base) or L2 testnets use a Basescan API key (but still call it `--etherscan-api-key` in the command): <https://basescan.org/myapikey>
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.eridian.xyz/ethereum-dev/foundry-notes/useful-commands/forge.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
