Class: MTX

primitives.MTX(options)

MTX A mutable transaction object.

Constructor

new MTX(options)

Create a mutable transaction.

Extends:
  • TX
Parameters:
Name Type Description
options Object
Properties:
Name Type Description
changeIndex Number
view CoinView
Source:

Extends

  • TX

Methods

(static) fromTX(tx) → {MTX}

Instantiate MTX from TX.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
MTX

(static) isMTX(obj) → {Boolean}

Test whether an object is an MTX.

Parameters:
Name Type Description
obj Object
Source:
Returns:
Type
Boolean

addCoin(coin) → {Input}

Add a coin as an input. Note that this will add the coin to the internal coin viewpoint.

Parameters:
Name Type Description
coin Coin
Source:
Returns:
Type
Input
Example
mtx.addCoin(Coin.fromTX(tx, 0, -1));

addInput(options) → {Input}

Add an input to the transaction.

Parameters:
Name Type Description
options Input | Object
Source:
Returns:
Type
Input
Example
mtx.addInput({ prevout: { hash: ... }, witness: ... });
mtx.addInput(new Input());

addOutpoint(outpoint) → {Input}

Add an outpoint as an input.

Parameters:
Name Type Description
outpoint Outpoint | Object
Source:
Returns:
Type
Input
Example
mtx.addOutpoint({ hash: ..., index: 0 });
mtx.addOutpoint(new Outpoint(hash, index));

addOutput(addr, valuenullable) → {Output}

Add an output.

Parameters:
Name Type Attributes Description
addr Address | Output | Object

Address or output options.

value Amount <nullable>
Source:
Returns:
Type
Output
Example
mtx.addOutput(new Output());
mtx.addOutput({ address: ..., value: 100000 });
mtx.addOutput(address, 100000);

addTX(tx, index, heightnullable) → {Input}

Add a transaction as an input. Note that this will add the coin to the internal coin viewpoint.

Parameters:
Name Type Attributes Description
tx TX
index Number
height Number <nullable>
Source:
Returns:
Type
Input
Example
mtx.addTX(tx, 0);

avoidFeeSniping(height)

Avoid fee sniping.

Parameters:
Name Type Description
height Number

Current chain height.

Source:
See:
  • bitcoin/src/wallet/wallet.cpp

check(flagsopt) → {Boolean}

Verify all transaction inputs.

Parameters:
Name Type Attributes Default Description
flags VerifyFlags <optional>
STANDARD_VERIFY_FLAGS
Source:
Throws:

on invalid inputs

Type
ScriptError
Returns:

Whether the inputs are valid.

Type
Boolean

checkAsync(flagsopt, nullable, poolnullable) → {Promise}

Verify the transaction inputs on the worker pool (if workers are enabled).

Parameters:
Name Type Attributes Default Description
flags VerifyFlags <optional>
<nullable>
STANDARD_VERIFY_FLAGS
pool WorkerPool <nullable>
Source:
Returns:
Type
Promise

checkInputs(height) → {Array}

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 Description
height 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.

Source:
Returns:

[fee, reason, score]

Type
Array

commit() → {Array}

Convert the MTX to a TX.

Source:
Returns:

[tx, view]

Type
Array

(async) estimateSize(estimatenullable) → {Number}

Estimate maximum possible size.

Parameters:
Name Type Attributes Description
estimate function <nullable>

Input script size estimator.

Source:
Returns:
Type
Number

format() → {Object}

Inspect the transaction.

Source:
Returns:
Type
Object

fromJSON(json)

Inject properties from a json object.

Parameters:
Name Type Description
json Object
Source:

(private) fromOptions(options)

Inject properties from options object.

Parameters:
Name Type Description
options Object
Source:

fromTX(tx) → {MTX}

Instantiate MTX from TX.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
MTX

(async) fund(coins, options) → {CoinSelector}

Select coins and fill the inputs.

Parameters:
Name Type Description
coins Array.<Coin>
options Object

See MTX#selectCoins options.

Source:
Returns:
Type
CoinSelector

getAddresses() → {Array.<Address>}

Get all addresses.

Source:
Returns:

addresses

Type
Array.<Address>

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.<Address>}

Get all input addresses.

Source:
Returns:

addresses

Type
Array.<Address>

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

getJSON(network) → {Object}

Convert transaction to JSON.

Parameters:
Name Type Description
network Network
Source:
Returns:
Type
Object

getSigops(flagsnullable) → {Number}

Calculate virtual sigop count.

Parameters:
Name Type Attributes Description
flags VerifyFlags <nullable>
Source:
Returns:

sigop count

Type
Number

getSigopsSize() → {Number}

Calculate the virtual size of the transaction (weighted against bytes per sigop cost).

Source:
Returns:

vsize

Type
Number

hasCoins() → {Boolean}

Test whether the transaction has all coins available/filled.

Source:
Returns:
Type
Boolean

inject() → {MTX}

Clone the transaction. Note that this will not carry over the view.

Source:
Returns:
Type
MTX

isInputSigned(index, coin) → {Boolean}

Test whether an input is fully-signed.

Parameters:
Name Type Description
index Number
coin Coin | Output
Source:
Returns:
Type
Boolean

isSigned() → {Boolean}

Test whether the transaction is fully-signed.

Source:
Returns:
Type
Boolean

isVectorSigned(prev, vector) → {Boolean}

Test whether a vector is fully-signed.

Parameters:
Name Type Description
prev Script
vector Stack
Source:
Returns:
Type
Boolean

scriptInput(index, coin, ring) → {Boolean}

Build input script (or witness) templates (with OP_0 in place of signatures).

Parameters:
Name Type Description
index Number

Input index.

coin Coin | Output
ring KeyRing
Source:
Returns:

Whether the script was able to be built.

Type
Boolean

scriptVector(prev, ring) → {Boolean}

Build script for a single vector based on a previous script.

Parameters:
Name Type Description
prev Script
ring Buffer
Source:
Returns:
Type
Boolean

selectCoins(coins, optionsnullable) → {CoinSelection}

Select necessary coins based on total output value.

Parameters:
Name Type Attributes Description
coins Array.<Coin>
options Object <nullable>
Source:
Throws:

on not enough funds available.

Returns:
Type
CoinSelection

setLocktime(locktime, secondsnullable)

Set locktime and sequences appropriately.

Parameters:
Name Type Attributes Description
locktime Number
seconds Boolean <nullable>
Source:

setSequence(index, locktime, secondsnullable)

Set sequence locktime.

Parameters:
Name Type Attributes Description
index Number

Input index.

locktime Number
seconds Boolean <nullable>
Source:

sign(ring, type) → {Number}

Built input scripts (or witnesses) and sign the inputs.

Parameters:
Name Type Description
ring KeyRing

Address used to sign. The address must be able to redeem the coin.

type SighashType
Source:
Returns:

Number of inputs signed.

Type
Number

(async) signAsync(ring, typenullable, poolnullable) → {Promise}

Sign the transaction inputs on the worker pool (if workers are enabled).

Parameters:
Name Type Attributes Description
ring KeyRing
type SighashType <nullable>
pool WorkerPool <nullable>
Source:
Returns:
Type
Promise

signInput(index, coin, ring, type) → {Boolean}

Sign an input.

Parameters:
Name Type Description
index Number

Index of input being signed.

coin Coin | Output
ring KeyRing

Private key.

type SighashType
Source:
Returns:

Whether the input was able to be signed.

Type
Boolean

(async) signInputAsync(index, coin, ring, typenullable, poolnullable) → {Promise}

Sign a transaction input on the worker pool (if workers are enabled).

Parameters:
Name Type Attributes Description
index Number
coin Coin | Output
ring KeyRing
type SighashType <nullable>
pool WorkerPool <nullable>
Source:
Returns:
Type
Promise

signVector(prev, vector, sig, ring) → {Boolean}

Add a signature to a vector based on a previous script.

Parameters:
Name Type Description
prev Script
vector Stack
sig Buffer
ring KeyRing
Source:
Returns:
Type
Boolean

sortMembers()

Sort inputs and outputs according to BIP69.

Source:
See:

subtractFee(fee)

Attempt to subtract a fee from all outputs evenly.

Parameters:
Name Type Description
fee Amount
Source:

subtractIndex(index, fee)

Attempt to subtract a fee from a single output.

Parameters:
Name Type Description
index Number
fee Amount
Source:

template(ring) → {Number}

Build input scripts (or witnesses).

Parameters:
Name Type Description
ring KeyRing

Address used to sign. The address must be able to redeem the coin.

Source:
Returns:

Number of inputs templated.

Type
Number

toJSON() → {Object}

Convert transaction to JSON.

Source:
Returns:
Type
Object

toTX() → {TX}

Convert the MTX to a TX.

Source:
Returns:
Type
TX

verify(flagsopt) → {Boolean}

Verify all transaction inputs.

Parameters:
Name Type Attributes Default Description
flags VerifyFlags <optional>
STANDARD_VERIFY_FLAGS
Source:
Returns:

Whether the inputs are valid.

Type
Boolean

(async) verifyAsync(flagsopt, nullable, poolnullable) → {Promise}

Verify the transaction inputs on the worker pool (if workers are enabled).

Parameters:
Name Type Attributes Default Description
flags VerifyFlags <optional>
<nullable>
STANDARD_VERIFY_FLAGS
pool WorkerPool <nullable>
Source:
Returns:
Type
Promise

verifyInputs(height) → {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 Description
height 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.

Source:
Returns:
Type
Boolean