Skip to content

TransactionEnvelopeEip1559.serialize

Serializes a TransactionEnvelopeEip1559.TransactionEnvelopeEip1559.

Imports

Named
import { TransactionEnvelopeEip1559 } from 'ox'

Examples

import { TransactionEnvelopeEip1559, Value } from 'ox'
 
const envelope = TransactionEnvelopeEip1559.from({
  chainId: 1,
  maxFeePerGas: Value.fromGwei('10'),
  maxPriorityFeePerGas: Value.fromGwei('1'),
  to: '0x0000000000000000000000000000000000000000',
  value: Value.fromEther('1'),
})
 
const serialized = TransactionEnvelopeEip1559.serialize(envelope)

Attaching Signatures

It is possible to attach a signature to the serialized Transaction Envelope.

import { Secp256k1, TransactionEnvelopeEip1559, Value } from 'ox'
 
const envelope = TransactionEnvelopeEip1559.from({
  chainId: 1,
  maxFeePerGas: Value.fromGwei('10'),
  maxPriorityFeePerGas: Value.fromGwei('1'),
  to: '0x0000000000000000000000000000000000000000',
  value: Value.fromEther('1'),
})
 
const signature = Secp256k1.sign({
  payload: TransactionEnvelopeEip1559.getSignPayload(envelope),
  privateKey: '0x...',
})
 
const serialized = TransactionEnvelopeEip1559.serialize(envelope, { 
  signature, 
})
 
// ... send `serialized` transaction to JSON-RPC `eth_sendRawTransaction`

Definition

function serialize(
  envelope: PartialBy<TransactionEnvelopeEip1559, 'type'>,
  options?: serialize.Options,
): Serialized

Source: src/TransactionEnvelopeEip1559.ts

Parameters

envelope

  • Type: PartialBy<TransactionEnvelopeEip1559, 'type'>

The Transaction Envelope to serialize.

options

  • Type: serialize.Options
  • Optional

Options.

options.signature

  • Type: { r: bigint; s: bigint; yParity: number; }
  • Optional

Signature to append to the serialized Transaction Envelope.

Return Type

The serialized Transaction Envelope.

TransactionEnvelopeEip1559.Serialized

Error Type

TransactionEnvelopeEip1559.serialize.ErrorType