ox
Version:
Ethereum Standard Library
184 lines • 7.62 kB
TypeScript
import type * as AccessList from './AccessList.js';
import type * as Address from './Address.js';
import * as Authorization from './Authorization.js';
import * as Blobs from './Blobs.js';
import * as Errors from './Errors.js';
import * as Hex from './Hex.js';
import type { Compute } from './internal/types.js';
import type * as Kzg from './Kzg.js';
import * as TxEnvelope from './TxEnvelope.js';
/** A Transaction Request that is generic to all transaction types, as defined in the [Execution API specification](https://github.com/ethereum/execution-apis/blob/4aca1d7a3e5aab24c8f6437131289ad386944eaa/src/schemas/transaction.yaml#L358-L423). */
export type TransactionRequest<bigintType = bigint, numberType = number, type extends string = string> = Compute<{
/** EIP-2930 Access List. */
accessList?: AccessList.AccessList | undefined;
/** EIP-7702 Authorization List. */
authorizationList?: Authorization.ListSigned<bigintType, numberType> | undefined;
/** Versioned hashes of blobs to be included in the transaction. */
blobVersionedHashes?: readonly Hex.Hex[] | undefined;
/** Raw blob data. */
blobs?: readonly Hex.Hex[] | undefined;
/** EIP-155 Chain ID. */
chainId?: numberType | undefined;
/** Contract code or a hashed method call with encoded args */
data?: Hex.Hex | undefined;
/** @alias `data` – added for TransactionEnvelope - Transaction compatibility. */
input?: Hex.Hex | undefined;
/** Sender of the transaction. */
from?: Address.Address | undefined;
/** Gas provided for transaction execution */
gas?: bigintType | undefined;
/** Base fee per gas. */
gasPrice?: bigintType | undefined;
/** Maximum total fee per gas sender is willing to pay for blob gas (in wei). */
maxFeePerBlobGas?: bigintType | undefined;
/** Total fee per gas in wei (gasPrice/baseFeePerGas + maxPriorityFeePerGas). */
maxFeePerGas?: bigintType | undefined;
/** Max priority fee per gas (in wei). */
maxPriorityFeePerGas?: bigintType | undefined;
/** Unique number identifying this transaction */
nonce?: bigintType | undefined;
/** Transaction recipient */
to?: Address.Address | null | undefined;
/** Transaction type */
type?: type | undefined;
/** Value in wei sent with this transaction */
value?: bigintType | undefined;
/** ECDSA signature r. */
r?: Hex.Hex | undefined;
/** ECDSA signature s. */
s?: Hex.Hex | undefined;
/** ECDSA signature yParity. */
yParity?: numberType | undefined;
/** @deprecated ECDSA signature v (for backwards compatibility). */
v?: numberType | undefined;
}>;
/** RPC representation of a {@link ox#TransactionRequest.TransactionRequest}. */
export type Rpc = TransactionRequest<Hex.Hex, Hex.Hex, string>;
/**
* Converts a {@link ox#TransactionRequest.Rpc} to a {@link ox#TransactionRequest.TransactionRequest}.
*
* @example
* ```ts twoslash
* import { TransactionRequest } from 'ox'
*
* const request = TransactionRequest.fromRpc({
* to: '0x0000000000000000000000000000000000000000',
* value: '0x2386f26fc10000'
* })
* ```
*
* @param request - The RPC request to convert.
* @returns A transaction request.
*/
export declare function fromRpc(request: Rpc): TransactionRequest;
export declare namespace fromRpc {
type ErrorType = Authorization.fromRpcList.ErrorType | Hex.toNumber.ErrorType | Hex.toBigInt.ErrorType | Errors.GlobalErrorType;
}
/**
* Converts a {@link ox#TransactionRequest.TransactionRequest} to a {@link ox#TransactionRequest.Rpc}.
*
* @example
* ```ts twoslash
* import { TransactionRequest, Value } from 'ox'
*
* const request = TransactionRequest.toRpc({
* to: '0x0000000000000000000000000000000000000000',
* value: Value.fromEther('0.01')
* })
* ```
*
* @example
* ### Using with a Provider
*
* You can use {@link ox#Provider.(from:function)} to instantiate an EIP-1193 Provider and
* send a transaction to the Wallet using the `eth_sendTransaction` method.
*
* ```ts twoslash
* import 'ox/window'
* import { Provider, TransactionRequest, Value } from 'ox'
*
* const provider = Provider.from(window.ethereum!)
*
* const request = TransactionRequest.toRpc({
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* value: Value.fromEther('0.01')
* })
*
* const hash = await provider.request({
* // [!code focus]
* method: 'eth_sendTransaction', // [!code focus]
* params: [request] // [!code focus]
* }) // [!code focus]
* ```
*
* @param request - The request to convert.
* @returns An RPC request.
*/
export declare function toRpc(request: toRpc.Input): Rpc;
export declare namespace toRpc {
/** Numberish input accepted by {@link ox#TransactionRequest.(toRpc:function)}. */
type Input = TransactionRequest<Hex.Hex | bigint | number, Hex.Hex | number, string>;
type ErrorType = Authorization.toRpcList.ErrorType | Hex.fromNumber.ErrorType | Errors.GlobalErrorType;
}
/**
* Converts a {@link ox#TransactionRequest.TransactionRequest} to a {@link ox#(TransactionEnvelope:namespace).TxEnvelope}.
*
* Dispatches to the correct concrete envelope type via
* {@link ox#(TransactionEnvelope:namespace).(getType:function)} (using `request.type`
* when present, otherwise inferring from fee/blob/authorization fields), and
* drops fields that do not belong to the chosen type.
*
* For EIP-4844, if `blobs` is provided without `sidecars`, sidecars and
* `blobVersionedHashes` are derived via the `kzg` option. If `sidecars` is
* already provided, it is passed through unchanged.
*
* Inputs are expected to be in canonical form (`bigint` numerics and
* `'eip1559'`-style `type` strings). Pass RPC-shaped payloads through
* {@link ox#TransactionRequest.(fromRpc:function)} first.
*
* @example
* ```ts twoslash
* import { TransactionRequest } from 'ox'
*
* const envelope = TransactionRequest.toEnvelope({
* chainId: 1,
* maxFeePerGas: 1n,
* to: '0x0000000000000000000000000000000000000000',
* value: 1n
* })
* // @log: {
* // @log: chainId: 1,
* // @log: maxFeePerGas: 1n,
* // @log: to: '0x0000000000000000000000000000000000000000',
* // @log: type: 'eip1559',
* // @log: value: 1n,
* // @log: }
* ```
*
* @param request - The transaction request to convert.
* @param options - Options.
* @returns A transaction envelope.
*/
export declare function toEnvelope(request: TransactionRequest, options?: toEnvelope.Options): TxEnvelope.TxEnvelope;
export declare namespace toEnvelope {
type Options = {
/**
* KZG context used to derive EIP-4844 `sidecars` and `blobVersionedHashes`
* from raw `blobs`. Required when `blobs` is provided without `sidecars`
* or `blobVersionedHashes`.
*/
kzg?: Kzg.Kzg | undefined;
};
type ErrorType = TxEnvelope.getType.ErrorType | TxEnvelope.from.ErrorType | Blobs.toCommitments.ErrorType | Blobs.toCellProofs.ErrorType | Blobs.commitmentsToVersionedHashes.ErrorType | MissingKzgError | MissingAuthorizationListError | Errors.GlobalErrorType;
}
/** Thrown when a 4844 conversion is requested but no `kzg` context is provided. */
export declare class MissingKzgError extends Errors.BaseError {
readonly name = "TransactionRequest.MissingKzgError";
constructor();
}
/** Thrown when a 7702 conversion is requested but no `authorizationList` is provided. */
export declare class MissingAuthorizationListError extends Errors.BaseError {
readonly name = "TransactionRequest.MissingAuthorizationListError";
constructor();
}
//# sourceMappingURL=TransactionRequest.d.ts.map