Transactions (Tx)
Sending calls as transactions, in four functions. plan says how many
signatures the calls take, submit asks for one, wait follows what was submitted into a
block, and send is the three together. receipt says where one transaction stands now, and
waits for nothing. A Signer signs, the transport follows what was sent,
and every failure is a value with a message.
import { Effect } from "effect";import { type Call, Tx } from "@ethect/core";
const four = (calls: ReadonlyArray<Call.Call<unknown, unknown>>) => Effect.gen(function* () { const steps = yield* Tx.plan(calls); // one step per signature. Nothing is signed for (const step of steps) { const pending = yield* Tx.submit(step); // one signature. Hashes, or an id of the wallet yield* Tx.wait(pending); // in a block, as deep as asked } return yield* Tx.send(calls); // all of it, in one line });| Export | Kind | Description |
|---|---|---|
Tx.send(calls, options?) |
function | All of it: plan, then submit and wait for each signature. One call gives a receipt, several give the receipts in order. |
Tx.plan(calls, options?) |
function | How many signatures the calls take, and what is in each. Asks nothing of the user. |
Tx.submit(step, options?) |
function | One signature: a step, or calls to sign as one. Hands them to the network and does not wait. |
Tx.wait(pending, options?) |
function | Waits for what was submitted to be in a block, as deep as asked. Fails if it reverted. |
Tx.receipt(hash, options?) |
function | Where one transaction stands now, in one request: its receipt, or none when it is in no block. Waits for nothing. |
Tx.toJson(pending) |
function | What a signer answered, as text: for local storage, a cookie, a database. |
Tx.fromJson(text) |
function | The pending a text holds, or none. It never throws. |
Tx.simulate(calls, options?) |
function | Runs the calls in order, each seeing the ones before it. Sends nothing and needs no signer. |
Tx.Broadcast |
reference | How the bytes a local signer signed reach the network. |
Tx.Reverted |
error | A call reverted, on chain or before anything was sent. reason is typed by the errors given. |
Tx.Dropped |
error | A transaction left the mempool, another one took its nonce, or a wallet gave up on a batch. |
Tx.Unsupported |
error | The signer cannot do what was asked. reason says what. |
Tx.Partial |
error | Some of the calls went out before one was refused. sent has them. |
Tx.isOutcome(error) |
function | Whether a failed wait said how it ended: Tx.Reverted or Tx.Dropped. Anything else means nobody could tell. |
Tx.Failure<E> |
type | Everything sending can fail with. E is the errors the calls declare. |
Tx.Fields |
type | Transaction fields to set instead of leaving them to the wallet or to an estimate: nonce, gas, the fees, accessList, type. |
Tx.Step |
type | One thing to sign, as plan decided it. Today a Tx.Step.Calls: calls, atomic, from, chainId. |
Tx.Pending |
type | What a signer answered, as plain data: Tx.Transactions or Tx.Handle. |
Tx.Transactions |
type | Transaction hashes, one per call, with their sender and chain. With a local key, what each went out with: its nonce, its gas and its fees. |
Tx.Handle |
type | An id only the signer can resolve, such as a wallet batch. Tx.Handle.Status is where it stands. |
Tx.PlanOptions |
type | batch and from. |
Tx.SubmitOptions |
type | from, id, capabilities and transaction. |
Tx.WaitOptions |
type | confirmations, and the errors a revert may be. |
Tx.ReceiptOptions |
type | The errors a revert may be. |
Tx.SendOptions |
type | The options of the three, for send. |
Tx.SimulateOptions |
type | from, block, stateOverride and method. |
Tx.Simulation |
type | What simulated calls did: results, and gas when the node gave it. |
Failures
Section titled “Failures”| Failure | _tag |
Its message |
|---|---|---|
Tx.Reverted |
"TxReverted" |
built from call and reason: The call at index 1 reverted: paused. What the node said follows, when there is a cause |
Tx.Dropped |
"TxDropped" |
built from transaction and replacedBy |
Tx.Unsupported |
"TxUnsupported" |
given by the signer |
Tx.Partial |
"TxPartial" |
given by the signer |
Sending also fails with Signer.Rejected,
Signer.Error, AbiError and
Transport.Error. Tx.receipt fails with Tx.Reverted and
Transport.Error only. Tx.wait alone fails with
Transport.UnknownChain, for what was submitted on another chain. Each is on the page of the
failures.
Under the hood
Section titled “Under the hood”The signer signs, and the node says what is in a block. Each function has its requests on its page.
Tx.plan(calls)- the wallet
wallet_getCapabilitiesfor several calls: whether the wallet runs them as one. A local key is asked nothing
- the wallet
Tx.submit(step), with a wallet- the wallet
eth_chainIdis the wallet on the chain of the step? - the wallet
eth_sendTransactionone call: a hash - the wallet
wallet_sendCallsseveral calls: the id of a batch
- the wallet
Tx.submit(step), with a local key- your nodethe fees and the gas that are not set
- your node
eth_getTransactionCount(from, "pending")the first time only - your programthe transaction is signed
- your node
eth_sendRawTransactiononce per call
Tx.wait(pending)- your node
eth_getTransactionReceiptasked first, one per transaction. All in a block: no block is watched - your node
eth_getTransactionReceiptfor a transaction that is in no block yetat each head after the first - the wallet
wallet_getCallsStatusfor a batch, asked first: only its wallet knows the idat each head while the batch is pending
- your node
Tx.receipt(hash)- your node
eth_getTransactionReceipt(hash)once: the receipt, or none. Nothing is waited for
- your node
See Tx.plan, Tx.submit,
Tx.wait, Tx.receipt
and Tx.send.