> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Anvil Methods

> Anvil/Foundry RPC methods for local development and testing

## Overview

Anvil-specific RPC methods for controlling local test networks. These methods enable advanced testing scenarios like state manipulation, time travel, and account impersonation.

## Snapshot & Revert

### evm\_snapshot

Creates a snapshot of the current blockchain state.

```typescript theme={null}
import { anvil } from '@tevm/voltaire/jsonrpc';

const request = anvil.evm_snapshot();
// Returns: snapshot ID (e.g., "0x1")
```

### evm\_revert

Reverts the blockchain state to a previous snapshot.

```typescript theme={null}
const request = anvil.evm_revert('0x1');
// Returns: true if successful
```

**Example: Test rollback**

```typescript theme={null}
const snapshotId = await provider.request(anvil.evm_snapshot());

// Make state changes
await contract.mutate();

// Revert to snapshot
await provider.request(anvil.evm_revert(snapshotId));
```

## Time Manipulation

### evm\_mine

Mines one or more blocks.

```typescript theme={null}
// Mine single block
const request = anvil.evm_mine();

// Mine multiple blocks
const request = anvil.evm_mine(10);

// Mine with interval
const request = anvil.evm_mine(10, 5); // 10 blocks, 5s interval
```

### evm\_increaseTime

Fast-forwards time by the specified number of seconds.

```typescript theme={null}
const request = anvil.evm_increaseTime(3600); // +1 hour
```

### evm\_setNextBlockTimestamp

Sets the timestamp of the next block.

```typescript theme={null}
const request = anvil.evm_setNextBlockTimestamp(1700000000);
```

### evm\_setBlockGasLimit

Sets the block gas limit.

```typescript theme={null}
const request = anvil.evm_setBlockGasLimit('0x1c9c380'); // 30M gas
```

**Example: Time-based testing**

```typescript theme={null}
// Set specific timestamp
await provider.request(anvil.evm_setNextBlockTimestamp(1700000000));
await provider.request(anvil.evm_mine());

// Or increment time
await provider.request(anvil.evm_increaseTime(86400)); // +1 day
await provider.request(anvil.evm_mine());
```

## Account Impersonation

### anvil\_impersonateAccount

Start impersonating an account (send transactions without private key).

```typescript theme={null}
const request = anvil.anvil_impersonateAccount(
  '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
);
```

### anvil\_stopImpersonatingAccount

Stop impersonating an account.

```typescript theme={null}
const request = anvil.anvil_stopImpersonatingAccount(
  '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
);
```

**Example: Impersonation**

```typescript theme={null}
const whale = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';

await provider.request(anvil.anvil_impersonateAccount(whale));

// Send transactions as whale
await contract.connect(whale).transfer(recipient, amount);

await provider.request(anvil.anvil_stopImpersonatingAccount(whale));
```

## State Manipulation

### anvil\_setBalance

Sets the balance of an account.

```typescript theme={null}
const request = anvil.anvil_setBalance(
  '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  '0xde0b6b3a7640000' // 1 ETH
);
```

### anvil\_setCode

Sets the bytecode at an address.

```typescript theme={null}
const request = anvil.anvil_setCode(
  '0x5FbDB2315678afecb367f032d93F642f64180aa3',
  '0x6080604052...' // bytecode
);
```

### anvil\_setNonce

Sets the nonce of an account.

```typescript theme={null}
const request = anvil.anvil_setNonce(
  '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  '0x10'
);
```

### anvil\_setStorageAt

Sets the storage value at a specific slot.

```typescript theme={null}
const request = anvil.anvil_setStorageAt(
  '0x5FbDB2315678afecb367f032d93F642f64180aa3',
  '0x0', // slot
  '0x0000000000000000000000000000000000000000000000000000000000000001' // value
);
```

**Example: State setup**

```typescript theme={null}
// Fund test account
await provider.request(anvil.anvil_setBalance(
  testAccount,
  '0x56bc75e2d63100000' // 100 ETH
));

// Set storage slot
await provider.request(anvil.anvil_setStorageAt(
  tokenContract,
  '0x0', // balances[testAccount] slot
  '0x' + (1000n * 10n**18n).toString(16).padStart(64, '0')
));
```

## Mining Control

### evm\_setAutomine

Enables or disables automatic mining of blocks.

```typescript theme={null}
// Disable automine
const request = anvil.evm_setAutomine(false);

// Enable automine
const request = anvil.evm_setAutomine(true);
```

### evm\_setIntervalMining

Sets the mining interval in seconds (0 disables).

```typescript theme={null}
// Mine every 5 seconds
const request = anvil.evm_setIntervalMining(5);

// Disable interval mining
const request = anvil.evm_setIntervalMining(0);
```

**Example: Manual mining**

```typescript theme={null}
// Disable automine for batch operations
await provider.request(anvil.evm_setAutomine(false));

// Queue multiple transactions
await contract.tx1();
await contract.tx2();
await contract.tx3();

// Mine all at once
await provider.request(anvil.evm_mine());

// Re-enable automine
await provider.request(anvil.evm_setAutomine(true));
```

## Common Patterns

### Test Isolation

```typescript theme={null}
let snapshotId;

beforeEach(async () => {
  snapshotId = await provider.request(anvil.evm_snapshot());
});

afterEach(async () => {
  await provider.request(anvil.evm_revert(snapshotId));
});
```

### Fork Testing

```typescript theme={null}
// Impersonate whale
await provider.request(anvil.anvil_impersonateAccount(whale));

// Fund test account from whale
await token.connect(whale).transfer(testAccount, amount);

// Stop impersonation
await provider.request(anvil.anvil_stopImpersonatingAccount(whale));
```

### Gas Optimization Testing

```typescript theme={null}
// Set high gas limit
await provider.request(anvil.evm_setBlockGasLimit('0x5f5e100')); // 100M

// Run gas-heavy operations
await contract.batchOperation(largeArray);
```

## See Also

* [Hardhat Methods](https://voltaire.tevm.sh/jsonrpc-provider/hardhat-methods)
* [Error Handling](https://voltaire.tevm.sh/jsonrpc-provider/error-handling.md)
* [Foundry Anvil Docs](https://book.getfoundry.sh/reference/anvil/)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.