new TxReader(provider)
Create an instance of the txReader
Parameters:
| Name | Type | Description |
|---|---|---|
provider |
DaoType | The provider of the chain interface |
Returns:
reader - An instance of the TxReader class
- Type
- TxReader
Example
const TxReader = require('./txReader')
const DaoType = require('./daoFactory')
const reader = new TxReader(DaoType.BLOCKCYPHER)
Methods
-
<async> getTx(txref)
-
Return a tx from a txref. Because the txref contains the chain information it doesn't need to be provided to the method in order to resolve the tx on the chain
Parameters:
Name Type Description txrefstring The txref encoding the position of the transaction in the chain Returns:
tx - The transaction- Type
- Object
Example
const txid = async reader.getTx('tx1:rzqq-qqqq-qeqc-6sw') // returns a tx object with the txid '0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098' -
<async> getTxid(txref)
-
Return a txid from a txref. Because the txref contains the chain information it doesn't need to be provided to the method in order to resolve the tx on the chain
Parameters:
Name Type Description txrefstring The txref encoding the position of the transaction in the chain Returns:
txid - The transaction id- Type
- string
Example
const txid = async reader.getTxid('tx1:rzqq-qqqq-qeqc-6sw') // returns '0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098' -
<async> getTxref(chain, txid)
-
Return a txref from a txid. As the txid doesn't contain any information around which chain it can be found on, this needs to be passed to the method
Parameters:
Name Type Description chainBech32hrp The chain that the transaction is recorded in txidstring The txid to be used to create the txref Returns:
txref - The txref describing the position of the transaction- Type
- string
Example
const txref = async reader.getTxref( Bech32hrp.BTC_MAINNET, '0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098') // returns 'tx1:rzqq-qqqq-qeqc-6sw'