Skip to content

TxEnvelopeTempo.from

Converts an arbitrary transaction object into a Tempo Transaction Envelope.

Use this to create transaction envelopes with Tempo-specific features like batched calls, fee tokens, access keys, and scheduled execution. Attach a signature using the signature option after signing with TxEnvelopeTempo.getSignPayload.

Tempo Transaction Specification

Imports

Named
import { TxEnvelopeTempo } from 'ox/tempo'

Examples

import { Value } from 'ox'
import { TxEnvelopeTempo } from 'ox/tempo'
 
const envelope = TxEnvelopeTempo.from({ 
  chainId: 1, 
  calls: [{ 
    data: '0xdeadbeef', 
    to: '0x0000000000000000000000000000000000000000', 
  }], 
  maxFeePerGas: Value.fromGwei('10'), 
  maxPriorityFeePerGas: Value.fromGwei('1'), 
})

Attaching Signatures

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

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

From Serialized

It is possible to instantiate a Tempo Transaction Envelope from a TxEnvelopeTempo.Serialized value.

import { TxEnvelopeTempo } from 'ox/tempo'
 
const envelope = TxEnvelopeTempo.from('0x76f84a0182031184773594008477359400809470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000080c0808080')
{
chainId: 1,
calls: [{
data: '0xdeadbeef',
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
}],
maxFeePerGas: 10000000000n,
type: 'tempo',
}

Definition

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

Source: src/tempo/TxEnvelopeTempo.ts

Parameters

envelope

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

The transaction object to convert.

options

  • Type: from.Options<signature>
  • Optional

Options.

options.feePayerSignature

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

options.signature

  • Type: signature | Value
  • Optional

Return Type

A Tempo Transaction Envelope.

from.ReturnValue<envelope, signature>