Skip to content

MinedBlock

A block as a test node returns it right after mining it: the block in full, each transaction with the data its execution returned and why it reverted.

import { Effect } from "effect";
import { Anvil, Eth } from "@ethect/core/rpc";
const outcomes = Effect.gen(function* () {
const [from, to] = yield* Eth.accounts();
yield* Anvil.setAutomine(false);
yield* Eth.sendTransaction({ from, to, value: 1n });
const [block] = yield* Anvil.mineDetailed();
// block: MinedBlock.MinedBlock
return block?.transactions.map((transaction) => ({
output: transaction.output, // "0x"
reverted: transaction.revertReason !== undefined, // false
}));
});
Schema Type Describes Returned by
MinedBlock.schema MinedBlock.MinedBlock a mined block whose transactions carry their output and revertReason Anvil.mineDetailed, Evm.mineDetailed

Both methods return an array, one MinedBlock per block mined.

A MinedBlock has every field of a Block.Full: the header, the body and transactions in full. Each transaction is a Transaction of any type, with two more fields.

Field Type Notes
transactions ReadonlyArray<Transaction & { output?, revertReason? }> in the order of the block
transactions[].output Hex (optional) the data the execution returned: the return data, or the revert data
transactions[].revertReason string (optional) why the transaction reverted, as anvil decodes it
  • output of a transfer is "0x". A transaction that ran no code returned nothing.
  • A revert has both. For a transaction that reverted with the data 0xdeadbeef, anvil 1.9 sends output: "0xdeadbeef" and revertReason: "custom error 0xdeadbeef".
  • No revertReason on success. The key is absent, not null: test it with transaction.revertReason !== undefined.
  • Still a union. transaction.type tells the transaction types apart as in Transaction, and narrows the fees and the other fields a type has.
  • The status is in the receipt. A MinedBlock does not say "success" or "reverted": read Eth.getTransactionReceipt for that.