Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Mining Modes

Mining modes determine when transactions are included in blocks. Pick the mode that matches your scenario.

Available Mining Modes

  • Auto — mine after each transaction
  • Interval — mine at fixed time intervals
  • Manual — mine only when explicitly requested
  • Gas — mine when accumulated gas crosses a threshold
Auto Mining
const node = createTevmNode({
  miningConfig: { type: "auto" },
});
 
const txHash = await node.sendTransaction({ /* ... */ });
 
// Already confirmed
const receipt = await node.getTransactionReceipt({ hash: txHash });
console.log("Block number:", receipt.blockNumber);
Best for:
  • Auto: quick dev, immediate confirmation, instant-finality simulation.
  • Interval: time-dependent logic, realistic network conditions, pending queues.
  • Manual: deterministic tests, precise timing, mempool behavior.
  • Gas: gas-dependent behavior, block-fullness simulation, load testing.

Changing Mining Modes

You can switch modes at runtime:

await node.setMiningConfig({ type: "interval", interval: 5000 });
await node.setMiningConfig({ type: "manual" });

Event Handlers

mine() accepts handlers to observe blocks, receipts, and logs in real time:

import { createMemoryClient } from "tevm";
 
const client = createMemoryClient();
 
const result = await client.mine({
  blockCount: 2,
  onBlock: (block, next) => {
    console.log(`Block #${block.header.number} mined:`, {
      hash: block.hash().toString("hex"),
      timestamp: block.header.timestamp,
      gasUsed: block.header.gasUsed,
    });
    next?.();
  },
  onReceipt: (receipt, blockHash, next) => {
    console.log(`Receipt for tx ${receipt.transactionHash}:`, {
      blockHash,
      gasUsed: receipt.gasUsed,
    });
    next?.();
  },
  onLog: (log, receipt, next) => {
    console.log(`Log from ${log.address}:`, {
      topics: log.topics,
      data: log.data,
    });
    next?.();
  },
});

Best Practices

Pick by use case:
  • Development → auto (fastest feedback)
  • Testing → manual (deterministic)
  • Simulation → interval (realistic)
  • Load testing → gas (congestion)
const timeNode = createTevmNode({ miningConfig: { type: "interval", interval: 10000 } });
const deterministicNode = createTevmNode({ miningConfig: { type: "manual" } });
const gasNode = createTevmNode({ miningConfig: { type: "gas", gasLimit: 8000000 } });

Example: Comparing Modes

Comparative Example
import { createTevmNode } from 'tevm'
 
const autoNode = createTevmNode({ miningConfig: { type: 'auto' } })
const intervalNode = createTevmNode({
  miningConfig: { type: 'interval', interval: 12000 }
})
const manualNode = createTevmNode({ miningConfig: { type: 'manual' } })
 
await autoNode.sendTransaction({...})     // Mines immediately
await intervalNode.sendTransaction({...}) // Mines after interval
await manualNode.sendTransaction({...})   // Stays pending
await manualNode.mine()                   // Now mined

Related

Transaction Pool · Performance Profiler · Block Methods