TransactionRequest
A transaction as a caller describes it, for the methods that run, estimate, fill, sign or send one. Every field is optional: the node or wallet fills in what is missing.
import { Effect } from "effect";import { Address } from "@ethect/core";import { Eth, type TransactionRequest } from "@ethect/core/rpc";
const FROM = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");const TO = Address.makeUnsafe("0x70997970C51812dc3A010C7d01b50e0d17dc79C8");
const sent = Effect.gen(function* () { const request: TransactionRequest.TransactionRequest = { from: FROM, to: TO, value: 1n }; const gas = yield* Eth.estimateGas(request); return yield* Eth.sendTransaction({ ...request, gas });});A request is a plain object. The same one goes to several methods.
Schemas
Section titled “Schemas”| Schema | Type | Describes | Used by |
|---|---|---|---|
TransactionRequest.schema |
TransactionRequest.TransactionRequest |
a transaction request | the methods below |
| Method | What it does with the request |
|---|---|
Eth.call |
runs it without sending it |
Eth.estimateGas |
returns the gas it needs |
Eth.createAccessList |
returns the access list it would use |
Eth.simulateV1 |
runs it as one of the calls of a simulated block |
Eth.fillTransaction |
fills in what it leaves out |
Eth.signTransaction |
signs it |
Eth.sendTransaction, Eth.sendTransactionSync |
signs it and sends it |
Wallet.walletSendTransaction |
the same, under the name some wallets use |
Debug.traceCall |
runs it and traces it |
Anvil.sendUnsignedTransaction |
sends it from any account of a test node, without a signature |
Anvil.reorg |
puts it in one of the blocks that replace the latest ones |
Fields
Section titled “Fields”Every field is optional.
| Field | Type | Notes |
|---|---|---|
type |
Transaction.Type | Hex |
"legacy", "eip2930", "eip1559", "eip4844", "eip7702", or the raw type byte of another type |
from |
Address |
the sender |
to |
Address | null |
the recipient or the contract, left out or null to create a contract |
nonce |
number |
|
gas |
bigint |
the gas limit |
value |
bigint |
in wei |
data |
Hex |
the calldata, or the creation code of a contract |
input |
Hex |
the same, under the name a node returns it by: see below |
gasPrice |
bigint |
in wei, for a legacy or EIP-2930 transaction |
maxFeePerGas |
bigint |
in wei, since EIP-1559 |
maxPriorityFeePerGas |
bigint |
in wei, since EIP-1559 |
maxFeePerBlobGas |
bigint |
in wei, for an EIP-4844 transaction |
chainId |
number |
|
accessList |
AccessList |
since EIP-2930 |
blobVersionedHashes |
ReadonlyArray<Hash> |
for an EIP-4844 transaction |
blobs |
ReadonlyArray<Hex> |
for an EIP-4844 transaction |
commitments |
ReadonlyArray<Hex> |
for an EIP-4844 transaction |
proofs |
ReadonlyArray<Hex> |
for an EIP-4844 transaction |
authorizationList |
ReadonlyArray<Authorization> |
for an EIP-7702 transaction |
On the wire
Section titled “On the wire”The schema encodes the request: quantities become hex, the type becomes its byte, and addresses go out in their EIP-55 form.
import { Address } from "@ethect/core";import { Eth } from "@ethect/core/rpc";
const FROM = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");const TO = Address.makeUnsafe("0x70997970C51812dc3A010C7d01b50e0d17dc79C8");
const result = Eth.call({ type: "eip1559", from: FROM, to: TO, value: 10n ** 18n, nonce: 7, maxFeePerGas: 30n * 10n ** 9n,});{ "type": "0x2", "from": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", "to": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", "nonce": "0x7", "value": "0xde0b6b3a7640000", "maxFeePerGas": "0x6fc23ac00"}Behavior
Section titled “Behavior”- Write the calldata as
data. Nodes readdataorinput, and wallets only knowdata. Each is sent under the name you used. inputis for a transaction you read. ATransactionfrom a node has its calldata asinput, and it is sent when you pass one as a request.- Do not set both to different values. anvil 1.9 refuses a request whose
dataandinputdiffer, with anRpcErrorof reasonInvalidParams. - Other unknown keys are left out. A variable with more keys than a request has compiles,
and only the fields above are sent: the
hashandblockNumberof a transaction are not. - Leave out what you do not set. A field you do not give is not sent, and the node or
wallet chooses: the nonce of
from, an estimate of the gas, the fees. - No
tocreates a contract.datais then the creation code. - Nothing is built for you here. A request goes out as you wrote it.
datais calldata you bring:Call.encodebuilds it from a call.blobs,commitments,proofsand the signatures ofauthorizationListare yours too, and nothing in the library builds them. To have the fields filled, signed and sent, useTx.send. - Numbers. Wei and gas are
bigint.nonceandchainIdarenumber. See values on the wire.
A transaction read from a node
Section titled “A transaction read from a node”A transaction is accepted where a request is: its fields are a request’s, with the calldata as
input.
import { Eth, type Transaction } from "@ethect/core/rpc";
/** Runs a mined transaction again, on the latest state. */const replay = (transaction: Transaction.Eip1559) => { // The node filled in `gasPrice`: anvil refuses it next to a fee cap. const { gasPrice, ...request } = transaction; return Eth.call(request, "latest");};A legacy transaction goes back as it is. A mined EIP-1559 one carries the gasPrice the node
added, and anvil 1.9 refuses a request with both a gasPrice and a maxFeePerGas.