UnspentOutput

bitcore.Transaction.UnspentOutput is a class with stateless instances that provides information about an unspent output:

  • Transaction ID and output index
  • The "scriptPubKey", the script included in the output
  • Amount of satoshis associated
  • Address, if available

Parameters

The constructor is quite permissive with the input arguments. It can take outputs straight out of bitcoind's getunspent RPC call. Some of the names are not very informative for new users, so the UnspentOutput constructor also understands these aliases:

  • scriptPubKey: just script is also accepted
  • amount: expected value in BTC. If the satoshis alias is used, make sure to use satoshis instead of BTC.
  • vout: this is the index of the output in the transaction, renamed to outputIndex
  • txid: txId

Example

var utxo = new UnspentOutput({
  "txid" : "a0a08e397203df68392ee95b3f08b0b3b3e2401410a38d46ae0874f74846f2e9",
  "vout" : 0,
  "address" : "mgJT8iegL4f9NCgQFeFyfvnSw1Yj4M5Woi",
  "scriptPubKey" : "76a914089acaba6af8b2b4fb4bed3b747ab1e4e60b496588ac",
  "amount" : 0.00070000
});
var utxo = new UnspentOutput({
  "txId" : "a0a08e397203df68392ee95b3f08b0b3b3e2401410a38d46ae0874f74846f2e9",
  "outputIndex" : 0,
  "address" : "mgJT8iegL4f9NCgQFeFyfvnSw1Yj4M5Woi",
  "script" : "76a914089acaba6af8b2b4fb4bed3b747ab1e4e60b496588ac",
  "satoshis" : 70000
});

UnspentOutput

Kind: global class

new UnspentOutput(data)

Represents an unspent output information: its script, associated amount and address, transaction id and output index.

Param Type Description
data object
data.txid string the previous transaction id
[data.txId] string alias for txid
data.vout number the index in the transaction
[data.outputIndex] number alias for vout
data.scriptPubKey string | Script the script that must be resolved to release the funds
data.script string | Script alias for scriptPubKey
data.amount number amount of bitcoins associated
[data.satoshis] number alias for amount, but expressed in satoshis (1 BTC = 1e8 satoshis)
data.address string | Address the associated address to the script, if provided

unspentOutput.toObject ⇒ object

Returns a plain object (no prototype or methods) with the associated info for this output

Kind: instance property of UnspentOutput

unspentOutput.inspect() ⇒

Provide an informative output when displaying this object in the console

Kind: instance method of UnspentOutput
Returns: string

unspentOutput.toString() ⇒

String representation: just "txid:index"

Kind: instance method of UnspentOutput
Returns: string

UnspentOutput.fromObject(data) ⇒

Deserialize an UnspentOutput from an object

Kind: static method of UnspentOutput
Returns: UnspentOutput

Param Type
data object | string