Skip to content

TransactionEnvelopeEip7702.from

Converts an arbitrary transaction object into an EIP-7702 Transaction Envelope.

Imports

Named
import { TransactionEnvelopeEip7702 } from 'ox'

Examples

import { Authorization, Secp256k1, TransactionEnvelopeEip7702, Value } from 'ox'
 
const authorization = Authorization.from({
  address: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  chainId: 1,
  nonce: 0n,
})
 
const signature = Secp256k1.sign({
  payload: Authorization.getSignPayload(authorization),
  privateKey: '0x...',
})
 
const authorizationList = [Authorization.from(authorization, { signature })]
 
const envelope = TransactionEnvelopeEip7702.from({ 
  authorizationList, 
  chainId: 1, 
  maxFeePerGas: Value.fromGwei('10'), 
  maxPriorityFeePerGas: Value.fromGwei('1'), 
  to: '0x0000000000000000000000000000000000000000', 
  value: Value.fromEther('1'), 
})

Attaching Signatures

It is possible to attach a signature to the transaction envelope.

import { Secp256k1, TransactionEnvelopeEip7702, Value } from 'ox'
 
const envelope = TransactionEnvelopeEip7702.from({
  authorizationList: [...],
  chainId: 1,
  maxFeePerGas: Value.fromGwei('10'),
  maxPriorityFeePerGas: Value.fromGwei('1'),
  to: '0x0000000000000000000000000000000000000000',
  value: Value.fromEther('1'),
})
 
const signature = Secp256k1.sign({
  payload: TransactionEnvelopeEip7702.getSignPayload(envelope),
  privateKey: '0x...',
})
 
const envelope_signed = TransactionEnvelopeEip7702.from(envelope, { 
  signature, 
})
{
authorizationList: [...],
chainId: 1,
maxFeePerGas: 10000000000n,
maxPriorityFeePerGas: 1000000000n,
to: '0x0000000000000000000000000000000000000000',
type: 'eip7702',
value: 1000000000000000000n,
r: 125...n,
s: 642...n,
yParity: 0,
}

From Serialized

It is possible to instantiate an EIP-7702 Transaction Envelope from a TransactionEnvelopeEip7702.Serialized value.

import { TransactionEnvelopeEip7702 } from 'ox'
 
const envelope = TransactionEnvelopeEip7702.from('0x04f858018203118502540be4008504a817c800809470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000080c08477359400e1a001627c687261b0e7f8638af1112efa8a77e23656f6e7945275b19e9deed80261')
{
authorizationList: [...],
chainId: 1,
maxFeePerGas: 10000000000n,
to: '0x0000000000000000000000000000000000000000',
type: 'eip7702',
value: 1000000000000000000n,
}

Definition

function from<envelope, signature>(
  envelope: envelope | UnionPartialBy<TransactionEnvelopeEip7702, 'type'> | Serialized,
  options?: from.Options<signature>,
): from.ReturnType<envelope, signature>

Source: src/core/TransactionEnvelopeEip7702.ts

Parameters

envelope

  • Type: envelope | UnionPartialBy<TransactionEnvelopeEip7702, 'type'> | Serialized

The transaction object to convert.

options

  • Type: from.Options<signature>
  • Optional

Options.

options.signature

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

Return Type

An EIP-7702 Transaction Envelope.

from.ReturnType<envelope, signature>