# Hardhat

Hardhat works against AEREDIUM with no plugin or fork — just point it at the RPC.

## Configure

`hardhat.config.ts`:

```ts
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
  solidity: "0.8.24",
  networks: {
    aeredium: {
      url: "https://rpc.aeredium.io",
      chainId: 1000,
      accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
    },
  },
};

export default config;
```

Set your deployer key in `.env`:

```bash
PRIVATE_KEY=0xabcdef...
```

(Use `dotenv` or any secrets loader you prefer. **Never** commit a real key.)

## Compile and deploy

```bash
npx hardhat compile

# Run a deploy script against AEREDIUM
npx hardhat run scripts/deploy.ts --network aeredium
```

Example `scripts/deploy.ts`:

```ts
import { ethers } from "hardhat";

async function main() {
  const Counter = await ethers.getContractFactory("Counter");
  const counter = await Counter.deploy();
  await counter.waitForDeployment();
  console.log("Counter deployed to", await counter.getAddress());
}

main().catch((err) => {
  console.error(err);
  process.exit(1);
});
```

Because AEREDIUM has 1-block finality, `waitForDeployment()` returns as soon as the next block (\~2 seconds) lands.

## Verify on a block explorer

A native AEREDIUM block explorer is coming soon. In the meantime, you can read your contract's bytecode directly:

```bash
curl -X POST https://rpc.aeredium.io \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xYourContract","latest"],"id":1}'
```

## Forking AEREDIUM locally

For local testing against live state, start a Hardhat fork:

```ts
networks: {
  hardhat: {
    forking: {
      url: "https://rpc.aeredium.io",
      // Optional pin to a specific block:
      // blockNumber: 1234567,
    },
  },
},
```

Then run `npx hardhat node` — your tests can interact with mainnet contracts and balances at the forked block.

## Common gotchas

**`UNCONFIGURED_NAME` errors from ethers** Hardhat's ethers integration sometimes tries to ENS-resolve addresses. AEREDIUM has no ENS; pass raw `0x…` addresses directly and you're fine.

**Gas estimation says `out of gas`** Some upstream Hardhat versions assume Ethereum block gas limits. If `eth_estimateGas` reports an unrealistic value, set an explicit `gasLimit` on the deploy / call options.

**Receipts arrive too fast for tests waiting on confirmations** If a test hardcodes `tx.wait(5)`, drop it to `tx.wait(1)` — there's no benefit to waiting for more confirmations on a chain with 1-block finality.


---

# 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://aeredium.gitbook.io/developer.aeredium.io/tooling/hardhat.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.
