new TX(data)
A static transaction object.
Parameters:
Name | Type | Description |
---|---|---|
data |
NakedTX | Transaction fields. |
Properties:
Name | Type | Description |
---|---|---|
type |
String | "tx" (inv type). |
version |
Number | Transaction version. Note that BCoin reads versions as unsigned even though they are signed at the protocol level. This value will never be negative. |
flag |
Number | Flag field for segregated witness. Always non-zero (1 if not present). |
inputs |
Array.<Input> | |
outputs |
Array.<Output> | |
locktime |
Number | nLockTime |
ts |
Number | Timestamp of the block the transaction was included in (unix time). |
block |
Hash | null | Hash of the block the transaction was included in. |
index |
Number | Transaction's index in the block tx vector. |
ps |
Number | "Pending Since": The time at which the transaction was first seen. Only non-zero on unconfirmed transactions. |
changeIndex |
Number | Index of the change output (-1 if unknown). |
height |
Number | Height of the block the transaction was included in (-1 if unconfirmed). |
rblock |
ReversedHash | null | Reversed block hash (uint256le). |
rhash |
ReversedHash | Reversed transaction hash (uint256le). |
rwhash |
ReversedHash | Reversed witness transaction hash (uint256le). |
txid |
String | Transaction ID. |
wtxid |
String | Witness transaction ID (Same as txid if no witness is present. All zeroes if coinbase). |
- Source:
Methods
(static) fromExtended(data, saveCoinsnullable, encnullable) → {TX}
Instantiate a transaction from a Buffer in "extended" serialization format.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Buffer | ||
saveCoins |
Boolean |
<nullable> |
If true, the function will attempt to parse the coins. |
enc |
String |
<nullable> |
One of |
- Source:
Returns:
- Type
- TX
(static) fromJSON(json) → {TX}
Instantiate a transaction from a jsonified transaction object.
Parameters:
Name | Type | Description |
---|---|---|
json |
Object | The jsonified transaction object. |
- Source:
Returns:
- Type
- TX
(static) fromRaw(data, encnullable) → {TX}
Instantiate a transaction from a serialized Buffer.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Buffer | ||
enc |
String |
<nullable> |
Encoding, can be |
- Source:
Returns:
- Type
- TX
(static) getMinFee(sizenullable, ratenullable) → {Amount}
Calculate minimum fee based on rate and size.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
size |
Number |
<nullable> |
|
rate |
Rate |
<nullable> |
Rate of satoshi per kB. |
- Source:
Returns:
fee
- Type
- Amount
(static) getRate(size, fee) → {Rate}
Calculate a fee rate based on size and fees.
Parameters:
Name | Type | Description |
---|---|---|
size |
Number | |
fee |
Amount |
- Source:
Returns:
- Type
- Rate
(static) isTX(obj) → {Boolean}
Test whether an object is a TX.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object |
- Source:
Returns:
- Type
- Boolean
(static) parseExtended(data, saveCoinsnullable, encnullable) → {NakedTX}
Parse a transaction in "extended" serialization format.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Buffer | ||
saveCoins |
Boolean |
<nullable> |
If true, the function will attempt to parse the coins. |
enc |
String |
<nullable> |
One of |
- Source:
Returns:
- A "naked" transaction object.
- Type
- NakedTX
(static) parseJSON(json) → {NakedTX}
Handle a deserialized JSON transaction object.
Parameters:
Name | Type | Description |
---|---|---|
json |
Object |
- Source:
Returns:
A "naked" transaction (a plain javascript object which is suitable for passing to the TX constructor).
- Type
- NakedTX
(static) parseRaw(data, encnullable) → {NakedTX}
Parse a serialized transaction.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Buffer | ||
enc |
String |
<nullable> |
Encoding, can be |
- Source:
Returns:
A "naked" transaction object.
- Type
- NakedTX
checkInputs(spendHeight, retnullable) → {Boolean}
Perform contextual checks to verify input, output, and fee values, as well as coinbase spend maturity (coinbases can only be spent 100 blocks or more after they're created). Note that this function is consensus critical.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
spendHeight |
Number | Height at which the transaction is being spent. In the mempool this is the chain height plus one at the time it entered the pool. |
|
ret |
Object |
<nullable> |
Return object, may be
set with properties |
- Source:
Returns:
- Type
- Boolean
clone() → {TX}
Clone the transaction.
- Source:
Returns:
- Type
- TX
fillCoins(coins) → {Boolean}
Attempt to connect coins to prevouts.
Parameters:
Name | Type | Description |
---|---|---|
coins |
Coin | TX | Array.<Coin> | Array.<TX> |
- Source:
Returns:
Whether the transaction is now completely filled.
- Type
- Boolean
getAddresses() → {Array.<Base58Address>}
Get all addresses.
- Source:
Returns:
addresses
- Type
- Array.<Base58Address>
getBaseSize() → {Number}
Calculate the size of the transaction without the witness. with the witness included.
- Source:
Returns:
size
- Type
- Number
getConfirmations(heightnullable) → {Number}
Calculate current number of transaction confirmations.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
height |
Number |
<nullable> |
Current chain height. If not present, network chain height will be used. |
- Source:
Returns:
confirmations
- Type
- Number
getCost() → {Number}
Calculate the cost of the transaction. Note that this is cached.
- Source:
Returns:
cost
- Type
- Number
getFee() → {Amount}
Calculate the fee for the transaction.
- Source:
Returns:
fee (zero if not all coins are available).
- Type
- Amount
getHashes() → {Array.<Hash>}
Get all address hashes.
- Source:
Returns:
hashes
- Type
- Array.<Hash>
getInputAddresses() → {Array.<Base58Address>}
Get all input addresses.
- Source:
Returns:
addresses
- Type
- Array.<Base58Address>
getInputHashes() → {Array.<Hash>}
Get all input address hashes.
- Source:
Returns:
hashes
- Type
- Array.<Hash>
getInputValue() → {Amount}
Calculate the total input value.
- Source:
Returns:
value
- Type
- Amount
getLegacySigops() → {Number}
Calculate legacy (inaccurate) sigop count.
- Source:
Returns:
sigop count
- Type
- Number
getMinFee(sizenullable, ratenullable) → {Amount}
Calculate minimum fee in order for the transaction to be relayable (not the constant min relay fee).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
size |
Number |
<nullable> |
If not present, max size estimation will be calculated and used. |
rate |
Rate |
<nullable> |
Rate of satoshi per kB. |
- Source:
Returns:
fee
- Type
- Amount
getModifiedSize(sizenullable) → {Number}
Calculate the modified size of the transaction. This is used in the mempool for calculating priority.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
size |
Number |
<nullable> |
The size to modify. If not present, virtual size will be used. |
- Source:
Returns:
Modified size.
- Type
- Number
getOutputAddresses() → {Array.<Base58Address>}
Get all output addresses.
- Source:
Returns:
addresses
- Type
- Array.<Base58Address>
getOutputHashes() → {Array.<Hash>}
Get all output address hashes.
- Source:
Returns:
hashes
- Type
- Array.<Hash>
getOutputValue() → {Amount}
Calculate the total output value.
- Source:
Returns:
value
- Type
- Amount
getPrevout() → {Array.<Hash>}
Get all unique outpoint hashes.
- Source:
Returns:
Outpoint hashes.
- Type
- Array.<Hash>
getPriority(heightnullable, sizenullable) → {Object}
Calculate the transaction priority.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
height |
Number |
<nullable> |
If not present, tx height or mempool height will be used. |
size |
Number |
<nullable> |
Size to calculate priority based on. If not present, modified size will be calculated and used. |
- Source:
Returns:
data - Object containing
priority
and value
.
- Type
- Object
getRate(sizenullable) → {Rate}
Calculate the transaction's rate based on size and fees. Size will be calculated if not present.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
size |
Number |
<nullable> |
- Source:
Returns:
- Type
- Rate
getRaw() → {Buffer}
Serialize the transaction. Note that this is cached. This will use the witness serialization if a witness is present.
- Source:
Returns:
Serialized transaction.
- Type
- Buffer
getRoundFee(sizenullable, ratenullable) → {Amount}
Calculate the minimum fee in order for the transaction to be relayable, but _round to the nearest kilobyte when taking into account size.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
size |
Number |
<nullable> |
If not present, max size estimation will be calculated and used. |
rate |
Rate |
<nullable> |
Rate of satoshi per kB. |
- Source:
Returns:
fee
- Type
- Amount
getScripthashSigops() → {Number}
Calculate accurate sigop count, taking into account redeem scripts.
- Source:
Returns:
sigop count
- Type
- Number
getSigops(flagsnullable) → {Number}
Calculate virtual sigop count.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
flags |
VerifyFlags |
<nullable> |
- Source:
Returns:
sigop count
- Type
- Number
getSigopsCost(flagsnullable) → {Number}
Calculate sigops cost, taking into account witness programs.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
flags |
VerifyFlags |
<nullable> |
- Source:
Returns:
sigop cost
- Type
- Number
getSize() → {Number}
Calculate the real size of the transaction with the witness included.
- Source:
Returns:
size
- Type
- Number
getSizes() → {Object}
Calculate real size and size of the witness bytes.
- Source:
Returns:
Contains size
and witnessSize
.
- Type
- Object
getVirtualSize() → {Number}
Calculate the virtual size of the transaction. Note that this is cached.
- Source:
Returns:
vsize
- Type
- Number
hasCoins() → {Boolean}
Test whether the transaction has all coins available/filled.
- Source:
Returns:
- Type
- Boolean
hash(encnullable) → {Hash|Buffer}
Hash the transaction with the non-witness serialization.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
enc |
String |
<nullable> |
Can be |
- Source:
Returns:
hash
- Type
- Hash | Buffer
hasStandardInputs(flagsnullable) → {Boolean}
Perform contextual checks to verify coin and input script standardness (including the redeem script).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
flags |
VerifyFlags |
<nullable> |
- Source:
- See:
-
- AreInputsStandard()
Returns:
- Type
- Boolean
hasWitness() → {Boolean}
Test whether the transaction has a non-empty witness.
- Source:
Returns:
- Type
- Boolean
inspect() → {Object}
Inspect the transaction and return a more user-friendly representation of the data.
- Source:
Returns:
- Type
- Object
isCoinbase() → {Boolean}
Test whether the transaction is a coinbase by examining the inputs.
- Source:
Returns:
- Type
- Boolean
isFinal(height, ts) → {Boolean}
Check finality of transaction by examining nLockTime and nSequences.
Parameters:
Name | Type | Description |
---|---|---|
height |
Number | Height at which to test. This is usually the chain height, or the chain height + 1 when the transaction entered the mempool. |
ts |
Number | Time at which to test. This is usually the chain tip's parent's median time, or the time at which the transaction entered the mempool. If MEDIAN_TIME_PAST is enabled this will be the median time of the chain tip's previous entry's median time. |
- Source:
Returns:
- Type
- Boolean
Example
tx.isFinal(network.height + 1, utils.now());
isFree(heightnullable, sizenullable) → {Boolean}
Determine whether the transaction is above the free threshold in priority. A transaction which passed this test is most likely relayable without a fee.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
height |
Number |
<nullable> |
If not present, tx height or mempool height will be used. |
size |
Number |
<nullable> |
If not present, modified size will be calculated and used. |
- Source:
Returns:
- Type
- Boolean
isSane(retnullable) → {Boolean}
Non-contextual sanity checks for the transaction. Will mostly verify coin and output values.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
ret |
Object |
<nullable> |
Return object, may be
set with properties |
- Source:
- See:
-
- CheckTransaction()
Returns:
sane
- Type
- Boolean
isStandard(retnullable) → {Boolean}
Non-contextual checks to determine whether the transaction has all standard output script types and standard input script size with only pushdatas in the code. Will mostly verify coin and output values.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
ret |
Object |
<nullable> |
Return object, may be
set with properties |
- Source:
- See:
-
- IsStandardTx()
Returns:
- Type
- Boolean
isWatched(filter) → {Boolean}
Test a transaction against a bloom filter using
the BIP37 matching algorithm. Note that this may
update the filter depending on what the update
value is.
Parameters:
Name | Type | Description |
---|---|---|
filter |
Bloom |
- Source:
- See:
-
- "Filter matching algorithm":
- https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki
Returns:
True if the transaction matched.
- Type
- Boolean
maxSize() → {Number}
Estimate the max possible size of transaction once the inputs are scripted. If the transaction is non-mutable, this will just return the virtual size.
- Source:
Returns:
size
- Type
- Number
render() → {Buffer}
Serialize the transaction. Note that this is cached. This will use the witness serialization if a witness is present.
- Source:
Returns:
Serialized transaction.
- Type
- Buffer
renderNormal() → {Buffer}
Serialize the transaction without the witness vector, regardless of whether it is a witness transaction or not.
- Source:
Returns:
Serialized transaction.
- Type
- Buffer
renderWitness() → {Buffer}
Serialize the transaction with the witness vector, regardless of whether it is a witness transaction or not.
- Source:
Returns:
Serialized transaction.
- Type
- Buffer
setBlock(block, index)
Set the block the transaction was included in.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | MerkleBlock | |
index |
Number |
- Source:
signatureHash(index, prev, type, version) → {Buffer}
Get the signature hash of the transaction for signing verifying.
Parameters:
Name | Type | Description |
---|---|---|
index |
Number | Index of input being signed/verified. |
prev |
Script | Previous output script or redeem script (in the case of witnesspubkeyhash, this should be the generated p2pkh script). |
type |
SighashType | Sighash type. |
version |
Number | Sighash version (0=legacy, 1=segwit). |
- Source:
Returns:
Signature hash.
- Type
- Buffer
testInputs(addressMap, indexnullable) → {Boolean}
Test the inputs against an address, an array of address hashes, or a map of address hashes.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
addressMap |
Hash | Array.<Hash> | AddressHashMap | ||
index |
Number |
<nullable> |
- Source:
Returns:
Whether the transaction matched.
- Type
- Boolean
testOutputs(addressMap, indexnullable) → {Boolean}
Test the outputs against an address, an array of address hashes, or a map of address hashes.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
addressMap |
Hash | Array.<Hash> | AddressHashMap | ||
index |
Number |
<nullable> |
- Source:
Returns:
Whether the transaction matched.
- Type
- Boolean
toCoins() → {Coins}
Convert transaction outputs to a {Coins} object.
- Source:
Returns:
- Type
- Coins
toExtended(saveCoinsnullable, encnullable) → {Buffer}
Serialize a transaction to BCoin "extended format". This is the serialization format BCoin uses internally to store transactions in the database. The extended serialization includes the height, block hash, index, timestamp, pending-since time, and optionally a vector for the serialized coins.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
saveCoins |
Boolean |
<nullable> |
Whether to serialize the coins. |
enc |
String |
<nullable> |
One of |
- Source:
Returns:
- Type
- Buffer
toInv() → {InvItem}
Convert the tx to an inv item.
- Source:
Returns:
- Type
- InvItem
toJSON() → {Object}
Convert the transaction to an object suitable for JSON serialization. Note that the hashes will be reversed to abide by bitcoind's legacy of little-endian uint256s.
- Source:
Returns:
- Type
- Object
toRaw(encnullable) → {Buffer|String}
Serialize the transaction.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
enc |
String |
<nullable> |
Encoding, can be |
- Source:
- See:
Returns:
- Type
- Buffer | String
unsetBlock()
Remove all relevant block data from the transaction.
- Source:
verify(indexnullable, forcenullable, flagsnullable) → {Boolean}
Verify the transaction inputs.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
index |
Number |
<nullable> |
Index of output being verified. If not present, all outputs will be verified. |
force |
Boolean |
<nullable> |
Force the transaction to be verified, even if it has been confirmed. |
flags |
VerifyFlags |
<nullable> |
- Source:
Returns:
Whether the inputs are valid.
- Type
- Boolean
verifyAsync(indexnullable, forcenullable, flagsnullable, callback) → {Boolean}
Verify the transaction inputs on the worker pool (if workers are enabled).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
index |
Number |
<nullable> |
Index of output being verified. If not present, all outputs will be verified. |
force |
Boolean |
<nullable> |
Force the transaction to be verified, even if it has been confirmed. |
flags |
VerifyFlags |
<nullable> |
|
callback |
function |
- Source:
Returns:
Whether the inputs are valid.
- Type
- Boolean
witnessHash(encnullable) → {Hash|Buffer}
Hash the transaction with the witness serialization, return the wtxid (normal hash if no witness is present, all zeroes if coinbase).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
enc |
String |
<nullable> |
Can be |
- Source:
Returns:
hash
- Type
- Hash | Buffer