Onchain.Tempo.Transaction.Builder (onchain_tempo v0.1.1)

Copy Markdown View Source

Builds and signs Tempo Transactions (EIP-2718 type 0x76).

Constructs a 13-field unsigned RLP envelope (key_authorization omitted when absent), signs with secp256k1 (domain 0x76), and appends the sender_signature as the 14th field.

0x76 Field Layout

0x76 || rlp([
  chain_id, max_priority_fee_per_gas, max_fee_per_gas, gas_limit,
  calls, access_list, nonce_key, nonce,
  valid_before, valid_after, fee_token, fee_payer_signature,
  aa_authorization_list, sender_signature
])

key_authorization? is optional — omitted entirely when absent. The Tempo node discriminates by peeking at the next byte (>= 0xc0 = list = present).

Dependencies

Uses Signet.Signer.Curvy for signing (keccak + secp256k1), Signet.Recover for recovery bit, ExRLP for RLP encoding, and Onchain.RPC for nonce fetching. All available transitively via onchain.

Summary

Functions

Build and sign a fee-payer transaction with arbitrary calls.

Build and sign a TIP-20 transfer with fee payer placeholder.

Build and sign a 0x76 transaction with arbitrary calls.

Build and sign a TIP-20 transfer transaction (0x76).

Functions

build_fee_payer_multicall(opts)

@spec build_fee_payer_multicall(keyword()) :: {:ok, String.t()} | {:error, term()}

Build and sign a fee-payer transaction with arbitrary calls.

Accepts a :calls list of [to, value, input] RLP-ready tuples. Sets fee payer placeholder and empty fee token, same as build_fee_payer_transfer/1.

build_fee_payer_transfer(opts)

@spec build_fee_payer_transfer(keyword()) :: {:ok, String.t()} | {:error, term()}

Build and sign a TIP-20 transfer with fee payer placeholder.

Same as build_signed_transfer/1 but sets fee_payer_signature to <<0x00>> (placeholder) and fee_token to <<>> (empty), signaling the server should co-sign as fee payer.

Accepts the same options as build_signed_transfer/1. The :fee_token option is ignored (always empty for fee payer mode).

build_signed_multicall(opts)

@spec build_signed_multicall(keyword()) :: {:ok, String.t()} | {:error, term()}

Build and sign a 0x76 transaction with arbitrary calls.

Options (required)

  • :private_key — hex-encoded secp256k1 private key (with or without 0x prefix)
  • :calls — non-empty list of RLP-ready [to, value, input] call tuples
  • :chain_id — Tempo chain ID (integer)
  • :rpc_url — RPC endpoint for nonce fetching
  • :fee_token — TIP-20 token address (hex) used for fee payment

Options (optional)

  • :nonce_key — 2D nonce lane (integer, default 0)
  • :nonce — explicit nonce (skips RPC fetch if provided)
  • :gas_limit — gas limit (default 500000)
  • :valid_before — Unix timestamp (default 0 = no expiry)
  • :valid_after — Unix timestamp (default 0)

Returns

  • {:ok, hex_string}"0x76..." hex-encoded signed transaction
  • {:error, reason} — on signing or RPC failure

build_signed_transfer(opts)

@spec build_signed_transfer(keyword()) :: {:ok, String.t()} | {:error, term()}

Build and sign a TIP-20 transfer transaction (0x76).

Options (required)

  • :private_key — hex-encoded secp256k1 private key (with or without 0x prefix)
  • :token — TIP-20 token address (hex)
  • :recipient — transfer recipient address (hex)
  • :amount — transfer amount in base units (integer)
  • :chain_id — Tempo chain ID (integer)
  • :rpc_url — RPC endpoint for nonce fetching

Options (optional)

  • :fee_token — token address for fee payment (hex); defaults to :token value
  • :nonce_key — 2D nonce lane (integer, default 0)
  • :nonce — explicit nonce (skips RPC fetch if provided)
  • :gas_limit — gas limit (default 500000)
  • :valid_before — Unix timestamp (default 0 = no expiry)
  • :valid_after — Unix timestamp (default 0)

Returns

  • {:ok, hex_string}"0x76..." hex-encoded signed transaction
  • {:error, reason} — on signing or RPC failure