# `BSV.Transaction`
[🔗](https://github.com/Bittoku/bsv_sdk_elixir/blob/main/lib/bsv/transaction/transaction.ex#L1)

Bitcoin SV transaction.

# `t`

```elixir
@type t() :: %BSV.Transaction{
  inputs: [BSV.Transaction.Input.t()],
  lock_time: non_neg_integer(),
  outputs: [BSV.Transaction.Output.t()],
  version: non_neg_integer()
}
```

# `add_input`

```elixir
@spec add_input(t(), BSV.Transaction.Input.t()) :: t()
```

Append an input to the transaction.

# `add_input_from`

```elixir
@spec add_input_from(
  t(),
  String.t(),
  non_neg_integer(),
  String.t(),
  non_neg_integer()
) ::
  {:ok, t()} | {:error, term()}
```

Add an input from hex-encoded txid, vout, locking script, and satoshi amount.

# `add_output`

```elixir
@spec add_output(t(), BSV.Transaction.Output.t()) :: t()
```

Append an output to the transaction.

# `calc_input_signature_hash`

```elixir
@spec calc_input_signature_hash(t(), non_neg_integer(), non_neg_integer()) ::
  {:ok, &lt;&lt;_::256&gt;&gt;} | {:error, term()}
```

Compute the BIP-143 signature hash for the input at `input_index` using the given sighash flag.

# `from_binary`

```elixir
@spec from_binary(binary()) :: {:ok, t(), binary()} | {:error, term()}
```

Parse a transaction from raw binary. Returns `{:ok, tx, remaining_bytes}` on success.

# `from_hex`

```elixir
@spec from_hex(String.t()) :: {:ok, t()} | {:error, term()}
```

Parse a transaction from a hex-encoded string.

# `is_coinbase?`

```elixir
@spec is_coinbase?(t()) :: boolean()
```

Check if this is a coinbase transaction (null txid input with vout 0xFFFFFFFF).

# `new`

```elixir
@spec new() :: t()
```

Create a new empty transaction.

# `size`

```elixir
@spec size(t()) :: non_neg_integer()
```

Compute the serialized size of the transaction in bytes.

# `to_binary`

```elixir
@spec to_binary(t()) :: binary()
```

Serialize the transaction to raw binary (wire format).

# `to_hex`

```elixir
@spec to_hex(t()) :: String.t()
```

Serialize the transaction to a lowercase hex string.

# `total_input_satoshis`

```elixir
@spec total_input_satoshis(t()) :: {:ok, non_neg_integer()} | {:error, term()}
```

Sum the satoshi values of all source outputs referenced by inputs.

# `total_output_satoshis`

```elixir
@spec total_output_satoshis(t()) :: non_neg_integer()
```

Sum the satoshi values of all outputs.

# `tx_id`

```elixir
@spec tx_id(t()) :: &lt;&lt;_::256&gt;&gt;
```

Compute the 32-byte transaction ID (double-SHA256, internal byte order).

# `tx_id_hex`

```elixir
@spec tx_id_hex(t()) :: String.t()
```

Compute the transaction ID as a hex string in display order (byte-reversed).

# `txid_binary`

```elixir
@spec txid_binary(t()) :: binary()
```

Compute the transaction ID as raw 32 bytes (internal byte order).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
