Bitcoin block height tracker
Bitcore provides a very simple API for creating transactions. We expect this API to be accessible for developers without knowing the working internals of bitcoin in deep detail. What follows is a small introduction to transactions with some basic knowledge required to use this API. A Transaction contains a set of inputs and a set of outputs. Each input contains a reference to another transaction's output, and a signature that allows the value referenced in that output to be used in this transaction.
Note also that an output can be used only once. That's why there's a concept of "change address" in the bitcoin ecosystem: So, in order to transmit a valid transaction, you must know what other transactions on the network store outputs that have not been spent and that are available for you to spend meaning that you have the set of keys that can validate you own those funds.
The unspent outputs are usually referred to as "utxo"s. You can obtain the input and output total amounts of the transaction in satoshis by accessing the fields inputAmount and outputAmount. To send a transaction to a multisig address, the API is the same as in the above example. To spend outputs that require multiple signatures, the process needs extra information: Transaction inputs are instances of either Input or its subclasses.
They are stored in the input property of Transaction instances. Both PublicKeyHashInput and MultisigScriptHashInput cache the information about signatures, even though this information could somehow be encoded in the script. Both need to have the output property set in order to calculate the sighash so signatures can be created. A high level interface to add an input from a UTXO. It has a series of variants:.
Performs a series of checks on an input and appends it to the end of the input vector and updates the amount of incoming bitcoins of the transaction. This input uses the script property to mark the input as unsigned if the script is empty.
The isFullySigned method will only return true if all needed signatures are already added and valid. If addSignature is added after all need signatures are already set, an exception will be thrown. Returns an array of objects with the following properties:. To remove all outputs, you can use clearOutputswhich preserves change output configuration.
When serializing, the bitcore library performs a series of checks. These can be disabled by providing an object to the serialize method with the checks that you'll like to skip. When outputs' value don't sum up to the same amount that inputs, the difference in bitcoins goes to the miner of the block that includes this transaction.
The concept of a "change address" usually is associated with this: All bitcoin transactions contain a locktime field. The locktime indicates the earliest time a transaction can be added to the blockchain. Locktime allows signers to create time-locked transactions which will only become valid in the future, giving the signers a chance to change their minds.
Locktime can be set in the form of a bitcoin block height the transaction can only be included in a block with a higher height than specified or a linux timestamp transaction can only be confirmed after that time.
For more information see bitcoin's development guide section on locktime. You can also get a friendly version of the locktime field via Transaction getLockTime. We're expecting to have all of them by some time in Payment channel creation is available in the bitcore-channel module. Array - of objects that can be. PublicKeyInput - this, for chaining. PublicKeyHashInput - this, for chaining. Retrieve a hexa string that can be used with bitcoind's CLI interface decoderawtransaction, sendrawtransaction.
Retrieve a possible error that could appear when trying to serialize and broadcast this transaction. Sets nLockTime so that transaction is not valid until the desired date a timestamp in seconds since UNIX epoch is also accepted.
Add an input to this transaction. Can receive, as output information, the output of bitcoind's listunspent command, and a slightly fancier format recognized by bitcore:. Where address can be either a string or a bitcore Address object. The same is true for scriptwhich can be a string or a bitcore Script.
The input must be an instance of the Input class. It should have information about the Output that it's spending, but if it's not already set, two additional parameters, outputScript and satoshis can be provided.
Transaction this, for chaining. Add an input to this transaction, without checking that the input has information about the output that it's spending. Manually set the fee for this transaction. Transaction - this, for chaining. Manually set the fee per KB for this transaction. Output - change output, if it exists. Number - the transaction total output amount.
Number - the transaction total input amount. If there is no change output set, the fee is the total value of the outputs minus inputs. Note that a serialized transaction only specifies the value of its outputs.
The value of inputs are recorded in the previous transaction outputs being spent. This method therefore raises a "MissingPreviousOutput" error when called on a serialized transaction.
Number - fee of this transaction in satoshis. Transaction - this See: Randomize this transaction's outputs ordering. Sort this transaction's outputs, according to a given sorting function that takes an array as argument and returns a new array, with the same elements but with a different order. Sort this transaction's inputs, according to a given sorting function that takes an array as argument and returns a new array, with the same elements but with a different order.
Check that a transaction passes basic sanity tests. If not, return a string describing the error. This function contains the same logic as CheckTransaction in bitcoin core.
Determines if this transaction can be replaced in the mempool with another transaction that provides a sufficiently higher fee RBF. Enable this transaction to be replaced in the mempool RBF if a transaction includes a sufficiently higher fee.
Create a 'shallow' copy of the transaction, by serializing and deserializing it dropping any additional information that inputs and outputs may have hold. In case of a string, the UTF-8 representation will be stored.