Transaction (aka "tx") is an object that represents transfer of bitcoins
from one or more inputs to one or more outputs.
Use BTC::Transaction
class to inspect transactions or create them transactions manually.
To build transaction we recommend using BTC::TransactionBuilder,
which takes care of a lot of difficulties and exposes easy to use, yet powerful enough API.
Transactions are stored within blocks that form the block chain.
The first transaction in a block is called coinbase transaction. It has no inputs and the outputs contain collected mining fees and the mining reward (25 BTC per block as of March 2015).
Current version for all transactions. Equals 1
.
Default mining fee rate in satoshis per 1000 bytes. Equals 10000
.
Returns a new transaction initialized with a hex-encoded string in wire format.
Raises ArgumentError
if transaction is incomplete or incorrectly encoded.
Returns a new transaction initialized with a binary string in wire format.
Raises ArgumentError
if transaction is incomplete or incorrectly encoded.
Returns a new transaction initialized with data in wire format read from a given stream.
Raises ArgumentError
if transaction is incomplete or incorrectly encoded.
Returns a new transaction with named attributes. All attributes are optional and have appropriate default values.
Transaction.new(
version: 1,
inputs: [...],
outputs: [...],
lock_time: 0,
block_height: 319238,
...
)
Version of the transaction. Default value is BTC::Transaction::CURRENT_VERSION
.
List of TransactionInput objects. See also add_input
and remove_all_inputs
.
List of TransactionOutput objects. See also add_output
and remove_all_outputs
.
Lock time makes transaction not spendable until a designated time in the future.
Contains either a block height or a unix timestamp.
If this value is below LOCKTIME_THRESHOLD,
then it is treated as a block height. Default value is 0
.
These are not derived from transaction binary data, but set from some other source.
Binary hash of the block at which transaction was included.
If not confirmed or not available, equals nil
.
Read-write. Default value is nil
.
Hex big-endian hash of the block at which transaction was included.
See Hash↔ID Conversion.
If not confirmed or not available, equals nil
.
Read-write. Default value is nil
.
Height of the block at which transaction was included. If not confirmed equals -1
.
Note: block_height
might not be provided by some APIs while confirmations
may be.
Read-write. Default value is nil
.
Time of the block at which tx was included (Time
instance or nil
).
Read-write. Default value is nil
.
Number of confirmations for this transaction (depth in the blockchan).
Value 0
stands for unconfirmed transaction (stored in mempool).
Read-write. Default value is nil
.
If available, returns mining fee paid by this transaction.
If set, inputs_amount
is updated as (outputs_amount
+ fee
).
Read-write. Default value is nil
.
If available, returns total amount of all inputs.
If set, fee
is updated as (inputs_amount
- outputs_amount
).
Read-write. Default value is nil
.
Total amount on all outputs (not including fees). Always available because outputs contain their amounts.
Read-only.
32-byte transaction hash identifying the transaction.
Hex big-endian hash of the transaction. See Hash↔ID Conversion.
Binary representation of the transaction in wire format (aka payload).
Dictionary representation of transaction ready to be encoded in JSON, PropertyList etc.
Returns true
if this transaction generates new coins.
Returns a binary hash for signing a transaction (see BTC::Key#ecdsa_signature).
You should specify an input index, output script of the previous transaction for that input,
and an optional hash type (default is SIGHASH_ALL
).
Returns a hex representation of the transaction data
.
Returns a hex representation of the transaction data
.
Returns a complete copy of a transaction (each input and output is also copied via dup
).
Returns true
if both transactions have equal binary representation.
Adds a BTC::TransactionInput instance to a list of inputs
.
After being added, input will have its transaction
attribute set to the receiver.
Returns self
.
Adds a BTC::TransactionOutput instance to a list of outputs
.
After being added, output will have its transaction
attribute set to the receiver.
Returns self
.
Removes all inputs from the transaction and returns self
.
Removes all outputs from the transaction and returns self
.