Help us shape the future of Go! Take the 2026 Go Developer Survey

transaction

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: Apache-2.0, MIT Imports: 10 Imported by: 5

Documentation

Overview

Package transaction provides types and functions for working with Tempo Transactions.

TempoTransactions are Tempo's native account abstraction transaction type that support:

  • Batched calls: Execute multiple contract calls in a single transaction
  • 2D nonce system: Use sequence keys (nonceKey) for parallel transaction processing
  • Fee abstraction: Pay gas fees in stablecoins (e.g., AlphaUSD) instead of native tokens
  • Fee payer pattern: Allow third-party fee payers to sponsor transaction gas costs
  • Time-based validity: Set activation (validAfter) and expiration (validBefore) times

Basic Usage

Create and serialize a transaction:

tx := transaction.New()
tx.Gas = 100000
tx.AddCall(common.HexToAddress("0x..."), big.NewInt(0), []byte{})

// Sign the transaction
signer, _ := signer.NewSigner("0x...")
transaction.SignTransaction(tx, signer)

// Serialize to hex string
serialized, _ := transaction.Serialize(tx, nil)
// Returns: "0x76..." (ready to broadcast)

Deserialize a transaction:

tx, err := transaction.Deserialize("0x76...")
if err != nil {
	log.Fatal(err)
}

Fee Payer Pattern

The fee payer pattern allows a third party to pay gas fees:

// 1. User signs their transaction
userTx := transaction.New()
// ... configure transaction ...
transaction.SignTransaction(userTx, userSigner)

// 2. Fee payer adds their signature
transaction.AddFeePayerSignature(userTx, feePayerSigner)

// 3. Broadcast dual-signed transaction
serialized, _ := transaction.Serialize(userTx, nil)
// Broadcast to network...

2D Nonce System

Use nonceKey to enable parallel transactions:

// Transaction 1 with sequence A
tx1 := transaction.New()
tx1.NonceKey = big.NewInt(1) // Sequence A
tx1.Nonce = 0                 // First in sequence

// Transaction 2 with sequence B (can be processed in parallel)
tx2 := transaction.New()
tx2.NonceKey = big.NewInt(2) // Sequence B
tx2.Nonce = 0                 // First in sequence

Time-Based Validity

Set transaction validity windows:

tx := transaction.New()
tx.ValidAfter = uint64(time.Now().Unix())             // Activate now
tx.ValidBefore = uint64(time.Now().Add(1 * time.Hour).Unix()) // Expire in 1 hour

For more details on the TempoTransaction specification, see the Tempo documentation.

Example (BatchTransaction)

Example_batchTransaction demonstrates creating a transaction with multiple calls.

package main

import (
	"fmt"
	"math/big"

	"github.com/ethereum/go-ethereum/common"
	"github.com/tempoxyz/tempo-go/pkg/transaction"
)

func main() {
	tx := transaction.NewBuilder(big.NewInt(transaction.ChainIdMainnet)).
		SetGas(200000).
		SetMaxFeePerGas(big.NewInt(1000000000)).
		AddCall(
			common.HexToAddress("0x1111111111111111111111111111111111111111"),
			big.NewInt(0),
			[]byte{},
		).
		AddCall(
			common.HexToAddress("0x2222222222222222222222222222222222222222"),
			big.NewInt(0),
			[]byte{},
		).
		AddCall(
			common.HexToAddress("0x3333333333333333333333333333333333333333"),
			big.NewInt(0),
			[]byte{},
		).
		Build()

	fmt.Printf("Transaction has %d calls\n", len(tx.Calls))

}
Example (ClientUsage)

Example_clientUsage demonstrates using the RPC client.

package main

import (
	"context"
	"fmt"
	"math/big"

	"github.com/ethereum/go-ethereum/common"
	"github.com/tempoxyz/tempo-go/pkg/client"
	"github.com/tempoxyz/tempo-go/pkg/signer"
	"github.com/tempoxyz/tempo-go/pkg/transaction"
)

func main() {
	rpcClient := client.New(transaction.RpcUrlMainnet)

	sgn, _ := signer.NewSigner("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
	tx := transaction.NewBuilder(big.NewInt(transaction.ChainIdMainnet)).
		SetGas(100000).
		SetMaxFeePerGas(big.NewInt(1000000000)).
		AddCall(
			common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8"),
			big.NewInt(0),
			[]byte{},
		).
		Build()

	transaction.SignTransaction(tx, sgn)
	serialized, _ := transaction.Serialize(tx, nil)

	// Send to network (would fail in this example without a real node)
	ctx := context.Background()
	_, err := rpcClient.SendRawTransaction(ctx, serialized)

	// In a real application, check for errors
	fmt.Printf("Would send transaction, got error: %v\n", err != nil)

}
Output:
Would send transaction, got error: true
Example (FeePayerTransaction)

Example_feePayerTransaction demonstrates the fee payer pattern where a third party pays gas fees.

package main

import (
	"fmt"
	"log"
	"math/big"

	"github.com/ethereum/go-ethereum/common"
	"github.com/tempoxyz/tempo-go/pkg/signer"
	"github.com/tempoxyz/tempo-go/pkg/transaction"
)

func main() {
	sender, _ := signer.NewSigner("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
	feePayer, _ := signer.NewSigner("0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d")

	tx := transaction.NewBuilder(big.NewInt(transaction.ChainIdMainnet)).
		SetGas(100000).
		SetMaxFeePerGas(big.NewInt(1000000000)).
		AddCall(
			common.HexToAddress("0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC"),
			big.NewInt(0),
			[]byte{},
		).
		Build()

	transaction.SignTransaction(tx, sender)

	transaction.AddFeePayerSignature(tx, feePayer)

	recoveredSender, recoveredFeePayer, err := transaction.VerifyDualSignatures(tx)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Sender: %s, Fee Payer: %s\n",
		recoveredSender.Hex()[:10]+"...",
		recoveredFeePayer.Hex()[:10]+"...")

}
Example (SimpleTransaction)

Example_simpleTransaction demonstrates creating, signing, and sending a simple transaction.

package main

import (
	"fmt"
	"log"
	"math/big"

	"github.com/ethereum/go-ethereum/common"
	"github.com/tempoxyz/tempo-go/pkg/signer"
	"github.com/tempoxyz/tempo-go/pkg/transaction"
)

func main() {
	sgn, err := signer.NewSigner("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
	if err != nil {
		log.Fatal(err)
	}

	tx := transaction.NewBuilder(big.NewInt(transaction.ChainIdMainnet)).
		SetGas(100000).
		SetMaxFeePerGas(big.NewInt(1000000000)).
		SetMaxPriorityFeePerGas(big.NewInt(1000000)).
		AddCall(
			common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8"),
			big.NewInt(0),
			[]byte{},
		).
		Build()

	err = transaction.SignTransaction(tx, sgn)
	if err != nil {
		log.Fatal(err)
	}

	serialized, err := transaction.Serialize(tx, nil)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Transaction serialized: %s\n", serialized[:20]+"...")
}

Index

Examples

Constants

View Source
const (
	// TIP20TransferSelector is the transfer(address,uint256) selector without a 0x prefix.
	TIP20TransferSelector = "a9059cbb"
	// TIP20ApproveSelector is the approve(address,uint256) selector without a 0x prefix.
	TIP20ApproveSelector = "095ea7b3"
	// TIP20TransferWithMemoSelector is the transferWithMemo(address,uint256,bytes32) selector without a 0x prefix.
	TIP20TransferWithMemoSelector = "95777d59"
	// TIP20BurnAtSelector is the burnAt(address,uint256) selector without a 0x prefix.
	// burnAt is available from T12 (TIP-1006).
	TIP20BurnAtSelector = "9803f216"
)
View Source
const (
	// SignatureTypeSecp256k1 is the signature type for standard ECDSA signatures
	SignatureTypeSecp256k1 = "secp256k1"

	// SignatureTypeP256 is the signature type for P256 signatures
	SignatureTypeP256 = "p256"

	// SignatureTypeWebAuthn is the signature type for WebAuthn signatures
	SignatureTypeWebAuthn = "webauthn"

	// ChainIdMainnet is the chain ID for Tempo mainnet.
	ChainIdMainnet = 4217

	// ChainIdModerato is the chain ID for the Tempo Moderato testnet.
	ChainIdModerato = 42431

	// ChainIdDevnet is the chain ID for the Tempo devnet.
	ChainIdDevnet = 31318

	// RpcUrlMainnet is the RPC URL for Tempo mainnet.
	RpcUrlMainnet = "https://rpc.tempo.xyz"

	// RpcUrlModerato is the RPC URL for the Tempo Moderato testnet.
	RpcUrlModerato = "https://rpc.moderato.tempo.xyz"

	// DefaultNonceKey is the standard nonce key for sequential transactions.
	DefaultNonceKey = 0
)

Constants

Variables

View Source
var (
	// ErrNoSignature is returned when a transaction has no sender signature.
	ErrNoSignature = errors.New("transaction has no signature")

	// ErrNoFeePayerSignature is returned when a transaction has no fee payer signature.
	ErrNoFeePayerSignature = errors.New("transaction has no fee payer signature")

	// ErrMissingSenderSignature is returned when attempting to add a fee payer signature
	// to a transaction that doesn't have a sender signature yet.
	ErrMissingSenderSignature = errors.New("transaction must have sender signature before adding fee payer signature")

	// ErrInvalidTransaction is returned when a transaction cannot be parsed or is malformed.
	ErrInvalidTransaction = errors.New("invalid transaction")

	// ErrInvalidTransactionType is returned when a transaction has an unexpected type prefix.
	ErrInvalidTransactionType = errors.New("invalid transaction type")

	// ErrUnsupportedSignatureType is returned when attempting to verify a signature type
	// that cannot be verified via ecrecover (e.g., P256, WebAuthn, Keychain).
	ErrUnsupportedSignatureType = errors.New("unsupported signature type for verification")

	// ErrInvalidSignatureType is returned when a signature type is not allowed for the operation.
	// For example, fee payer signatures must be secp256k1.
	ErrInvalidSignatureType = errors.New("invalid signature type")
)

Sentinel errors for common error conditions. Use errors.Is() to check for specific error types.

View Source
var (
	// PathUSDAddress is Tempo's native fee token address.
	PathUSDAddress = common.HexToAddress("0x20c0000000000000000000000000000000000000")
	// FeeManagerAddress is the fee manager precompile.
	FeeManagerAddress = common.HexToAddress("0xfeec000000000000000000000000000000000000")
	// StablecoinDEXAddress is the stablecoin DEX precompile.
	StablecoinDEXAddress = common.HexToAddress("0xdec0000000000000000000000000000000000000")
	// AccountKeychainAddress is the account keychain precompile.
	AccountKeychainAddress = common.HexToAddress("0xaaaaaaaa00000000000000000000000000000000")
	// TIP20TransferTopic is the Transfer(address,address,uint256) event topic.
	TIP20TransferTopic = crypto.Keccak256Hash([]byte("Transfer(address,address,uint256)"))
	// TIP20TransferWithMemoTopic is the TransferWithMemo(address,address,uint256,bytes32) event topic.
	TIP20TransferWithMemoTopic = crypto.Keccak256Hash([]byte("TransferWithMemo(address,address,uint256,bytes32)"))
	// TIP20BurnAtRole is the BURN_AT_ROLE identifier required to call burnAt (T12+).
	TIP20BurnAtRole = crypto.Keccak256Hash([]byte("BURN_AT_ROLE"))
)

Common Tempo token and precompile addresses.

View Source
var (
	// AlphaUSDAddress is the address of the AlphaUSD stablecoin on Tempo.
	AlphaUSDAddress = common.HexToAddress("0x20c0000000000000000000000000000000000001")

	// NonceManagerAddress is the address of the Tempo Nonce Manager contract.
	// Used for querying nonces in the 2D nonce system.
	NonceManagerAddress = common.HexToAddress("0x4e4F4E4345000000000000000000000000000000")
)

Common Tempo contract addresses.

Functions

func AddFeePayerSignature

func AddFeePayerSignature(tx *Tx, sgn *signer.Signer) error

AddFeePayerSignature adds the fee payer signature to a transaction. The transaction must already have a sender signature.

func ComputeHash

func ComputeHash(serialized string) (common.Hash, error)

ComputeHash computes the Keccak256 hash of a serialized transaction. This is useful for verifying transaction hashes or implementing custom signing logic.

func EncodeTIP20BurnAtData added in v0.6.1

func EncodeTIP20BurnAtData(from common.Address, amount *big.Int) ([]byte, error)

EncodeTIP20BurnAtData encodes TIP-20 burnAt(address,uint256) calldata. The caller must hold BURN_AT_ROLE on the token; burnAt is available from T12 (TIP-1006).

func EncodeTIP20TransferData added in v0.4.1

func EncodeTIP20TransferData(recipient common.Address, amount *big.Int) ([]byte, error)

EncodeTIP20TransferData encodes TIP-20 transfer(address,uint256) calldata.

func EncodeTIP20TransferWithMemoData added in v0.4.1

func EncodeTIP20TransferWithMemoData(recipient common.Address, amount *big.Int, memo []byte) ([]byte, error)

EncodeTIP20TransferWithMemoData encodes TIP-20 transferWithMemo(address,uint256,bytes32) calldata.

func ExpiringNonceKey added in v0.6.1

func ExpiringNonceKey() *big.Int

ExpiringNonceKey returns a copy of the nonce key that marks an expiring nonce transaction (TIP-1009): 2^256 - 1. Expiring nonce transactions use validBefore for replay protection instead of sequential nonce state.

func GetFeePayerSignPayload

func GetFeePayerSignPayload(tx *Tx, sender common.Address) (common.Hash, error)

GetFeePayerSignPayload computes the hash that the fee payer should sign. This uses a different serialization format (0x78 prefix) and includes the sender address.

func GetSignPayload

func GetSignPayload(tx *Tx) (common.Hash, error)

GetSignPayload computes the hash that the sender should sign.

func ParseTopicAddress added in v0.4.1

func ParseTopicAddress(topic string) common.Address

ParseTopicAddress extracts the indexed address stored in an event topic. Invalid topics return the zero address.

func RecoverSigner added in v0.7.0

func RecoverSigner(tx *Tx) (signer.RecoveredSigner, error)

RecoverSigner verifies the sender signature of any type and returns its signer. For a Keychain signature, Account is the user address and KeyID the access key: whether the account authorized that key is on-chain state the caller must check (the AccountKeychain precompile).

func Serialize

func Serialize(tx *Tx, opts *SerializeOptions) (string, error)

Serialize serializes a TempoTransaction to hex string. Returns a string starting with TempoTransaction prefix "0x76" or "0x78" (if fee payer format).

func SerializeForFeePayerSigning

func SerializeForFeePayerSigning(tx *Tx, sender common.Address) (string, error)

SerializeForFeePayerSigning serializes a transaction for fee payer signing. This uses the 0x78 prefix and includes the sender address. IMPORTANT: Must remove BOTH sender and fee payer signatures (per tempo.ts reference).

func SerializeForSigning

func SerializeForSigning(tx *Tx) (string, error)

SerializeForSigning serializes a transaction for sender signing (without signatures). Per Tempo Transaction spec (https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction):

  • fee_token is SKIPPED (encoded as 0x80) when fee payer is involved
  • fee_token is INCLUDED when no fee payer (self-paid transaction)
  • feePayerSignatureOrSender field encoding:
  • If AwaitingFeePayer=true or FeePayerSignature is set: uses 0x00 marker
  • Otherwise: uses empty bytes (0x80)

This allows the fee payer to specify the fee token without invalidating the sender's signature.

func SignTransaction

func SignTransaction(tx *Tx, sgn *signer.Signer) error

SignTransaction signs a transaction with the sender's private key. This creates the sender signature envelope and adds it to the transaction.

func SignTransactionWith added in v0.7.0

func SignTransactionWith(tx *Tx, s signer.EnvelopeSigner) error

SignTransactionWith signs a transaction with any envelope signer: a secp256k1 Signer, a P256Signer or a WebAuthnSigner. The sender is the signer's address.

func VerifyDualSignatures

func VerifyDualSignatures(tx *Tx) (sender, feePayer common.Address, err error)

VerifyDualSignatures verifies both sender and fee payer signatures. Returns sender address, fee payer address, and any error.

func VerifyFeePayerSignature

func VerifyFeePayerSignature(tx *Tx, sender common.Address) (common.Address, error)

VerifyFeePayerSignature verifies the fee payer signature on a transaction. Per Tempo Transaction spec, fee payer signatures MUST be secp256k1. This is enforced by the type system: FeePayerSignature is *signer.Signature (not SignatureEnvelope).

func VerifySignature

func VerifySignature(tx *Tx) (common.Address, error)

VerifySignature verifies the sender signature on a transaction and returns the sender: the recovered secp256k1 address, or the address of the public key of a P256 or WebAuthn signature. Keychain (access key) signatures are rejected with ErrUnsupportedSignatureType: verify them with RecoverSigner or keychain.VerifyAccessKeySignature, then check the key's authorization on chain.

Types

type AccessList

type AccessList []AccessTuple

AccessList is an EIP-2930 access list.

type AccessTuple

type AccessTuple struct {
	Address     common.Address `json:"address"`
	StorageKeys []common.Hash  `json:"storageKeys"`
}

AccessTuple represents a single entry in an access list.

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder provides a fluent interface for constructing transactions. This makes it easier to build complex transactions with many optional fields.

Example usage:

tx := transaction.NewBuilder().
    SetGas(100000).
    AddCall(toAddress, big.NewInt(0), data).
    SetFeeToken(transaction.AlphaUSDAddress).
    Build()

func NewBuilder

func NewBuilder(chainID ...*big.Int) *Builder

NewBuilder creates a new transaction builder. Defaults to Tempo mainnet. An optional chain ID can be provided to target a different network.

func (*Builder) AddAccessListEntry

func (b *Builder) AddAccessListEntry(address common.Address, storageKeys []common.Hash) *Builder

AddAccessListEntry adds an entry to the access list.

func (*Builder) AddCall

func (b *Builder) AddCall(to common.Address, value *big.Int, data []byte) *Builder

AddCall adds a call to the transaction. The to address can be nil for contract creation. Value and data can be nil, they will be converted to empty bytes/zero.

func (*Builder) AddContractCreation

func (b *Builder) AddContractCreation(value *big.Int, data []byte) *Builder

AddContractCreation adds a contract creation call to the transaction.

func (*Builder) Build

func (b *Builder) Build() *Tx

Build returns the constructed transaction. Note: This does not validate the transaction. Call Validate() separately if needed.

func (*Builder) BuildAndValidate

func (b *Builder) BuildAndValidate() (*Tx, error)

BuildAndValidate returns the constructed transaction after validating it. This is a convenience method that ensures the transaction is valid before returning. Returns an error if validation fails.

func (*Builder) SetExpiringNonce added in v0.6.1

func (b *Builder) SetExpiringNonce(nonce uint64) *Builder

SetExpiringNonce marks the transaction as an expiring nonce transaction and sets its nonce discriminator. Pair it with SetValidBefore.

From T12 (TIP-1106), the nonce of an expiring nonce transaction is an opaque uint64 discriminator: distinct values let otherwise identical transactions be submitted in parallel within the same validity window. The SDK does not generate or track discriminators: callers choose the values and must keep them distinct for transactions that should not deduplicate. Before T12 the network requires nonce == 0.

func (*Builder) SetFeeToken

func (b *Builder) SetFeeToken(token common.Address) *Builder

SetFeeToken sets the token to use for paying gas fees.

func (*Builder) SetGas

func (b *Builder) SetGas(gas uint64) *Builder

SetGas sets the gas limit for the transaction.

func (*Builder) SetMaxFeePerGas

func (b *Builder) SetMaxFeePerGas(maxFee *big.Int) *Builder

SetMaxFeePerGas sets the maximum fee per gas.

func (*Builder) SetMaxPriorityFeePerGas

func (b *Builder) SetMaxPriorityFeePerGas(maxPriorityFee *big.Int) *Builder

SetMaxPriorityFeePerGas sets the maximum priority fee per gas.

func (*Builder) SetNonce

func (b *Builder) SetNonce(nonce uint64) *Builder

SetNonce sets the nonce for the transaction.

func (*Builder) SetNonceKey

func (b *Builder) SetNonceKey(nonceKey *big.Int) *Builder

SetNonceKey sets the nonce key (sequence key) for 2D nonce system.

func (*Builder) SetSponsored added in v0.2.1

func (b *Builder) SetSponsored(sponsored bool) *Builder

SetSponsored marks this transaction as sponsored (awaiting a fee payer signature). Per the Tempo Transaction spec, sponsored transactions encode fee_token as empty and fee_payer_signature field as 0x00 in the sender's signing payload. This MUST be called before SignTransaction if a fee payer will be added later.

func (*Builder) SetValidAfter

func (b *Builder) SetValidAfter(validAfter uint64) *Builder

SetValidAfter sets the activation timestamp for the transaction.

func (*Builder) SetValidBefore

func (b *Builder) SetValidBefore(validBefore uint64) *Builder

SetValidBefore sets the expiration timestamp for the transaction.

type Call

type Call struct {
	To    *common.Address `json:"to"`    // Target address (nil for contract creation)
	Value *big.Int        `json:"value"` // Amount to send in wei
	Data  []byte          `json:"data"`  // Call data
}

Call represents a single call within a TempoTransaction. Transactions can batch multiple calls together.

type SerializeFormat

type SerializeFormat int

SerializeFormat specifies the serialization format for a transaction.

const (
	// FormatNormal uses TempoTransaction prefix (0x76) for standard signing (default).
	FormatNormal SerializeFormat = iota
	// FormatFeePayer uses TempoTransaction fee payer prefix (0x78) for fee payer signing.
	FormatFeePayer
)

func (SerializeFormat) String

func (f SerializeFormat) String() string

String returns a human-readable representation of the serialize format. Implements the fmt.Stringer interface.

type SerializeOptions

type SerializeOptions struct {
	// Format specifies the serialization format.
	// FormatNormal (default) uses TempoTransaction prefix (0x76) for standard signing.
	// FormatFeePayer uses TempoTransaction fee payer prefix (0x78) for fee payer signing.
	Format SerializeFormat

	// Sender is the sender address, required when Format is FormatFeePayer.
	Sender common.Address

	// ForSigning indicates this is for computing a signing hash (not final broadcast).
	// When true and fee payer is involved, fee_token is skipped per Tempo spec.
	ForSigning bool
}

SerializeOptions contains options for serializing a transaction.

type Tx

type Tx struct {
	// Core transaction fields
	ChainID              *big.Int       `json:"chainId"`
	MaxPriorityFeePerGas *big.Int       `json:"maxPriorityFeePerGas"`
	MaxFeePerGas         *big.Int       `json:"maxFeePerGas"`
	Gas                  uint64         `json:"gas"`
	Calls                []Call         `json:"calls"`
	AccessList           AccessList     `json:"accessList"`
	NonceKey             *big.Int       `json:"nonceKey"`    // uint256 nonce key: 2D sequence key, or ExpiringNonceKey for expiring nonces
	Nonce                uint64         `json:"nonce"`       // Current value of the sequence key
	ValidBefore          uint64         `json:"validBefore"` // Optional expiration timestamp
	ValidAfter           uint64         `json:"validAfter"`  // Optional activation timestamp
	FeeToken             common.Address `json:"feeToken"`    // Stablecoin address for fees (e.g., AlphaUSD)

	// KeyAuthorization holds the decoded RLP keyAuthorization tuple for access key
	// transactions. Preserved as-is for re-serialization. Nil when not present.
	KeyAuthorization []interface{} `json:"keyAuthorization,omitempty"`

	// Signatures
	Signature         *signer.SignatureEnvelope `json:"signature"`         // Sender signature
	FeePayerSignature *signer.Signature         `json:"feePayerSignature"` // Fee payer signature (nil if not signed)

	// AwaitingFeePayer indicates the transaction was marked for fee payer sponsorship.
	// When true, serialization uses 0x00 marker
	// This is set when deserializing a transaction with feePayerSignature=null marker.
	AwaitingFeePayer bool `json:"-"`

	From common.Address `json:"from,omitempty"` // Sender address (recovered from signature)
}

Tx represents a Tempo Transaction

func Deserialize

func Deserialize(serialized string) (*Tx, error)

Deserialize parses a serialized TempoTransaction. The serialized transaction must start with TempoTransaction prefix "0x76".

RLP Structure: [

chainId,                      // 0
maxPriorityFeePerGas,         // 1
maxFeePerGas,                 // 2
gas,                          // 3
calls,                        // 4  Array of [to, value, data] tuples
accessList,                   // 5  Array of [address, [storageKeys]] tuples
nonceKey,                     // 6
nonce,                        // 7
validBefore,                  // 8
validAfter,                   // 9
feeToken,                     // 10
feePayerSignatureOrSender,    // 11 Signature [yParity, r, s] or "0x00" or empty
authorizationList,            // 12 Empty array (reserved for EIP-7702)
keyAuthorizationOrSignature,  // 13 (optional) keyAuthorization (list) or signatureEnvelope (bytes)
maybeSignature,               // 14 (optional) signatureEnvelope when field 13 is keyAuthorization

]

Field counts:

  • 13 fields: unsigned (no keyAuthorization, no signature)
  • 14 fields: signed (no keyAuthorization) OR unsigned with keyAuthorization
  • 15 fields: signed with keyAuthorization (access keys)

func New

func New() *Tx

New creates a new TempoTransaction with defaults for Tempo mainnet.

func NewDefault

func NewDefault(chainID int64) *Tx

NewDefault creates a new transaction with default values for the given chain ID.

func (*Tx) Clone

func (tx *Tx) Clone() *Tx

Clone creates a deep copy of the transaction. This is useful when you want to create variations of a transaction without modifying the original. Note that signatures are intentionally NOT copied since they are tied to specific transaction state.

Example usage:

template := transaction.NewDefault(transaction.ChainIdMainnet) // or omit for mainnet
template.SetGas(100000)

// Create variations for different recipients
tx1 := template.Clone()
tx1.Calls = []transaction.Call{{To: &recipient1, Value: amount1}}

tx2 := template.Clone()
tx2.Calls = []transaction.Call{{To: &recipient2, Value: amount2}}

func (*Tx) HasFeePayerSignature

func (tx *Tx) HasFeePayerSignature() bool

HasFeePayerSignature returns true if the transaction has a fee payer signature.

func (*Tx) Hash

func (tx *Tx) Hash() (common.Hash, error)

Hash computes the hash of a fully signed transaction. This returns the transaction hash that would appear on-chain: keccak256 of the serialized bytes, with secp256k1 recovery ids encoded as 27/28 as the node does. The transaction must be signed before calling this method.

func (*Tx) IsActive

func (tx *Tx) IsActive(currentTime uint64) bool

IsActive checks if the transaction is active based on validAfter.

func (*Tx) IsExpired

func (tx *Tx) IsExpired(currentTime uint64) bool

IsExpired checks if the transaction has expired based on validBefore.

func (*Tx) IsExpiringNonce added in v0.6.1

func (tx *Tx) IsExpiringNonce() bool

IsExpiringNonce reports whether the transaction uses the expiring nonce key.

func (*Tx) String

func (tx *Tx) String() string

String returns a human-readable representation of the transaction. Implements the fmt.Stringer interface for better debugging output.

func (*Tx) Validate

func (tx *Tx) Validate() error

Validate checks if the transaction is valid before signing/serializing. Returns an error if any required fields are missing or invalid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL