Transactions

Transactions in Bitcoin are cryptographically signed instructions to transfer ownership of bitcoin between accounts. They originate from a user's wallet and update the Bitcoin blockchain. Transactions are broadcast to the network and require verification by miners. Once verified, miners include them in a block, which is added to the blockchain, confirming the transfer. Bitcoin transactions must reference previous unspent outputs as inputs, and any unused portion can be returned as change or used to pay transaction fees.

In Bitcoin, transaction inputs and outputs follow a First-In-First-Out (FIFO) model. Inputs reference unspent transaction outputs (UTXOs) from previous transactions, consuming them in the order they are added. Outputs are created as new UTXOs, which can be spent in future transactions. When a transaction is processed, the oldest unspent inputs are used first, and any leftover value can be sent as change to a new output or used for transaction fees. This FIFO approach helps maintain the consistency and traceability of funds on the blockchain.

Sample Query

Select random transaction and get all inputs and outputs

with transaction_hash as (
    select hash from bitcoin.transactions limit 1
), inputs as (
    select 
        spent_utxo_id, 
        address0, 
        value, 
        'input' as input_or_output, 
        transaction_hash
    from bitcoin.enriched_inputs 
    where transaction_hash = (select hash from transaction_hash)
), outputs as (
    select 
        utxo_id, 
        address0, 
        value, 
        'input' as input_or_output, 
        transaction_hash
    from bitcoin.outputs 
    where transaction_hash = (select hash from transaction_hash)
)
select * from inputs 
union
select * from outputs;

Table Columns

This table is indexed by (hash, block_timestamp, block_hash) and has indicies on block_number and block_timestamp. Please use either index for faster queries.

Last updated