# Transactions

The class for creating transaction.

class `pybtc.``Transaction`(raw_tx=None, tx_format='decoded', version=1, lock_time=0, testnet=False)

  The class for Transaction object

  Parameters:

  - raw_tx – (optional) raw transaction in bytes or HEX encoded string, if no raw transaction provided well be created new empty transaction template.
  - tx_format – “raw” or “decoded” format. Raw format is mean that all transaction represented in bytes for best performance. Decoded transaction is represented in human readable format using base68, hex, bech32, asm and opcodes. By default “decoded” format using.
  - version (int) – transaction version for new template, by default 1.
  - lock_time (int) – transaction lock time for new template, by default 0.
  - testnet (boolean) – address type for “decoded” transaction representation.

  `decode`(testnet=None)

    change Transacion object representation to “decoded” human readable format

    Parameters: | testnet (bool) – (optional) address type for “decoded” transaction representation, by default None. if None used type from transaction property “format”.

  `encode`()

    change Transaction object representation to “raw” bytes format, all human readable part will be stripped.

  `json`()

    Get json transaction representation

  `serialize`(segwit=True, hex=True)

    Get serialized transaction

    Parameters:

    - segwit (bool) – (optional) flag for segwit representation of serialized transaction, by default True.
    - hex (bool) – (optional) if set to True return HEX encoded string, by default True.

    Return str,bytes:
    | serialized transaction in HEX or bytes.