Transaction class
Transactions are at the heart of this library. It is the primary means by which we interact with the Bitcoin network.
A Transaction will have one or more TransactionInputs that it is spending from and one or more TransactionOutputs which represent either the sending of coins to a recipient or the creation of 'data'-only output.
The raw hex transaction has the following layout:
4 bytes
- Transaction version number; currently version 1 or 2.
Programs creating transactions using er consensus rules may use higher version numbers.
Version 2 means that BIP 68 applies.
compactSize uint
- Number of inputs in this transaction.
VarByteArray
- Transaction inputs.
compactSize uint
- Number of outputs in this transaction.
VarByteArray
- Transaction outputs.
4 bytes
- A time (Unix epoch time) or block number. See the nLockTime parsing rules.
Constructors
- Transaction()
- Transaction.fromBufferReader(ByteDataReader reader)
- Constructs a transaction from a ByteDataReader which has been initialized with the raw hex data containing a complete transaction.
- Transaction.fromHex(String txnHex)
- Constructs a transaction instance from the raw hexadecimal string.
-
Transaction.fromJSONMap(LinkedHashMap<
String, dynamic> map) - Default constructor. Start empty, use the builder pattern to build a transaction.
Properties
- CURRENT_VERSION ↔ int
-
getter/setter pair
- DEFAULT_NLOCKTIME ↔ int
-
getter/setter pair
-
hash
→ List<
int> -
Returns the double-sha256 of the raw (hexadecimal) transaction
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
Returns the transaction ID.
no setter
-
inputs
→ List<
TransactionInput> -
Returns a list of all the
TransactionInput
sno setter - MAX_BLOCK_SIZE ↔ int
-
getter/setter pair
- nLockTime ↔ int
-
Gets the time until this transaction may be included in a block.
getter/setter pair
-
outputs
→ List<
TransactionOutput> -
Returns a list of all the
TransactionOutput
sno setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
transactionOptions
→ Set<
TransactionOption> -
Returns the current set of options that govern which checks are performed
when serializing to raw hex format.
no setter
- version ↔ int
-
Returns the transaction version number
getter/setter pair
Methods
-
addInput(
TransactionInput input) → Transaction -
addInputs(
dynamic inputs) → void -
addOutput(
TransactionOutput txOutput) → Transaction -
addOutputs(
dynamic outputs) → void -
getLockTime(
) → int - Returns either DateTime or int (blockHeight) Yes, the return type overloading sucks. Welcome to bitcoin.
-
isCoinbase(
) → bool -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
serialize(
) → String - Serialize the transaction object to it's raw hexadecimal representation, ready to be broadcast to the network, or to be passed to a peer. Returns the raw transaction as a hexadecimal string. Returns the raw transaction as a hexadecimal string, skipping all checks.
-
sort(
) → Transaction - Sort inputs and outputs according to Bip69
-
toObject(
) → Map< String, dynamic> - Renders this transaction as a Map/Object. See fromJSONMap() for example format.
-
toString(
) → String -
A string representation of this object.
inherited
-
verify(
) → void -
verifySignature(
SVSignature sig, SVPublicKey pubKey, int inputNumber, SVScript subscript, BigInt? satoshis, int flags) → bool
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- CHANGE_OUTPUT_MAX_SIZE → int
-
Safe upper bound for change address script size in bytes
final
- COIN_VALUE → BigInt
-
final
- DUST_AMOUNT → BigInt
-
Minimum amount for an output for it not to be considered a dust output
final
- FEE_SECURITY_MARGIN → BigInt
-
Margin of error to allow fees in the vecinity of the expected value but doesn't allow a big difference
final
- LOCKTIME_THRESHOLD → int
-
Threshold for lockTime: below this value it is interpreted as block number, otherwise as timestamp. *
final
- LOCKTIME_THRESHOLD_BIG → BigInt
-
TODO: Same but as a BigInteger for CHECKLOCKTIMEVERIFY
final
- MAX_COINS → int
-
final
- MAX_MONEY → BigInt
-
max amount of satoshis in circulation
final
- MAX_STANDARD_TX_SIZE → int
-
How many bytes a transaction can be before it won't be relayed anymore. Currently 100kb.
final
- MAXIMUM_EXTRA_SIZE → int
-
final
- NLOCKTIME_MAX_VALUE → int
-
Max value for an unsigned 32 bit value
final
- SCRIPT_MAX_SIZE → int
-
final
- SMALLEST_UNIT_EXPONENT → int
-
max amount of bitcoins in circulation
final