# Foundry

Foundry's `forge` and `cast` work against AEREDIUM out of the box. No special setup beyond pointing at the RPC.

## Configure

`foundry.toml`:

```toml
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc_version = "0.8.24"

[rpc_endpoints]
aeredium = "https://rpc.aeredium.io"

[etherscan]
# AEREDIUM does not yet have an Etherscan-compatible explorer.
# Skip --verify or use a custom verifier when one is available.
```

Set your deployer key (the standard Foundry pattern):

```bash
export AEREDIUM_RPC=https://rpc.aeredium.io
export PRIVATE_KEY=0xabcdef...
```

## Read the chain with `cast`

```bash
# Block height
cast block-number --rpc-url $AEREDIUM_RPC

# Balance
cast balance 0x742d35Cc6634C0532925a3b844Bc9e7595f3bA21 --rpc-url $AEREDIUM_RPC

# Chain ID (should print 1000)
cast chain-id --rpc-url $AEREDIUM_RPC

# Read a contract method
cast call 0xContract "balanceOf(address)(uint256)" 0xUser --rpc-url $AEREDIUM_RPC
```

## Send a transaction with `cast`

```bash
cast send 0xContract "transfer(address,uint256)" 0xRecipient 1000000000000000000 \
  --rpc-url $AEREDIUM_RPC \
  --private-key $PRIVATE_KEY
```

`cast send` waits for the receipt before returning — on AEREDIUM that's typically 2 seconds.

## Deploy with `forge create`

```bash
forge create src/Counter.sol:Counter \
  --rpc-url $AEREDIUM_RPC \
  --private-key $PRIVATE_KEY
```

For a multi-step deployment, write a `Script`:

```solidity
// script/Deploy.s.sol
pragma solidity ^0.8.24;

import "forge-std/Script.sol";
import "../src/Counter.sol";

contract DeployScript is Script {
    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        vm.startBroadcast(pk);
        Counter c = new Counter();
        c.increment();
        vm.stopBroadcast();
    }
}
```

Run it:

```bash
forge script script/Deploy.s.sol:DeployScript \
  --rpc-url $AEREDIUM_RPC \
  --broadcast
```

## Forking for tests

```bash
# One-off local node forked from AEREDIUM mainnet
anvil --fork-url $AEREDIUM_RPC

# Or in tests:
forge test --fork-url $AEREDIUM_RPC
```

In a test contract:

```solidity
contract LiveTest is Test {
    function setUp() public {
        vm.createSelectFork("https://rpc.aeredium.io");
    }

    function test_realState() public {
        // ...
    }
}
```

## Tracing and debugging

```bash
# Trace a tx by hash
cast run 0xTxHash --rpc-url $AEREDIUM_RPC

# Estimate gas
cast estimate 0xContract "method()" --rpc-url $AEREDIUM_RPC
```

## Tips

* AEREDIUM supports both legacy (type 0) and EIP-1559 (type 2) transactions. Foundry defaults to EIP-1559, which is recommended.
* Receipts include `effectiveGasPrice` so you can audit what each tx actually paid.
* For high-throughput batch sending, prefer `cast send --async` and poll receipts in parallel rather than awaiting each call.


---

# 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/foundry.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.
