IOTA transaction (de)serialization & guards.
Utilities and validators for transactions.
Install using npm:
```
npm install @iota/transaction
or using yarn:
``
yarn add @iota/transaction
* _static_
* [.transactionHash(buffer, [offset])](#module_transaction.transactionHash)
* [.isTransaction(transaction, [minWeightMagnitude])](#module_transaction.isTransaction)
* .isTailTransaction(transaction)
* .isHeadTransaction(transaction)
* _inner_
* ~isMultipleOfTransactionLength(lengthOrOffset)
* [~address(buffer, [offset])](#module_transaction..address)
* [~value(buffer, [offset])](#module_transaction..value)
* [~obsoleteTag(buffer, [offset])](#module_transaction..obsoleteTag)
* [~issuanceTimestamp(buffer, [offset])](#module_transaction..issuanceTimestamp)
* [~currentIndex(buffer, [offset])](#module_transaction..currentIndex)
* [~lastIndex(buffer, [offset])](#module_transaction..lastIndex)
* [~bundle(buffer, [offset])](#module_transaction..bundle)
* [~trunkTransaction(buffer, [offset])](#module_transaction..trunkTransaction)
* [~branchTransaction(buffer, [offset])](#module_transaction..branchTransaction)
* [~tag(buffer, [offset])](#module_transaction..tag)
* [~attachmentTimestamp(buffer, [offset])](#module_transaction..attachmentTimestamp)
* [~attachmentTimestampLowerBound(buffer, [offset])](#module_transaction..attachmentTimestampLowerBound)
* [~attachmentTimestampUpperBound(buffer, [offset])](#module_transaction..attachmentTimestampUpperBound)
* [~transactionNonce(buffer, [offset])](#module_transaction..transactionNonce)
* [~bundle(buffer, [offset])](#module_transaction..bundle)
- errors.ILLEGAL\_TRANSACTION\_BUFFER\_LENGTH : Make sure that the buffer argument contains 8,019 trits (the length of a transaction without the transaction hash).offset
- errors.ILLEGAL\_TRANSACTION\_OFFSET : Make sure that the argument is a multiple of 8,019 (the length of a transaction without the transaction hash).
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transactions in trits |
| [offset] | Number | 0 | Offset in trits to define a transaction to hash in the buffer argument |
This method takes transaction trits, and returns the transaction hash.
To validate the length of transaction trits, use the isMultipleOfTransactionLength() method.
To get a transaction's trits from the Tangle, use the getTrytes() method, then convert them to trits, using the trytesToTrits() method.
Returns: Int8Array - Transaction hash
Example
`js`
let hash = Transaction.transactionHash(transactions);
- errors.ILLEGAL\_MIN\_WEIGHT\_MAGNITUDE : Make sure that the minWeightMagnitude argument is a number between 1 and 81.transaction
- errors.ILLEGAL\_TRANSACTION\_BUFFER\_LENGTH : Make sure that the argument contains 8,019 trits (the length of a transaction without the transaction hash).
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| transaction | Int8Array | | Transaction trits |
| [minWeightMagnitude] | number | 0 | Minimum weight magnitude |
This method takes an array of transaction trits and validates whether they form a valid transaction by checking the following:
- Addresses in value transactions have a 0 trit at the end, which means they were generated using the Kerl hashing function
- The transaction would result in a valid hash, according to the given minWeightMagnitude argument
To get a transaction's trits from the Tangle, use the getTrytes() method, then convert them to trits, using the trytesToTrits() method.
Returns: boolean - valid - Whether the transaction is valid.
Example
`js`
let valid = Transaction.isTransaction(transaction);
- errors.ILLEGAL\_TRANSACTION\_BUFFER\_LENGTH : Make sure that the transaction argument contains 8,019 trits (the length of a transaction without the transaction hash).
| Param | Type | Description |
| --- | --- | --- |
| transaction | Int8Array | Transaction trits |
This method takes an array of transaction trits, and checks its currentIndex field to validate whether it is the tail transaction in a bundle.
To get a transaction's trits from the Tangle, use the getTrytes() method, then convert them to trits, using the trytesToTrits() method.
Returns: boolean - tail - Whether the transaction is a tail transaction.
Example
`js`
let tail = Transaction.isTailTransaction(transaction);
- errors.ILLEGAL\_TRANSACTION\_BUFFER\_LENGTH : Make sure that the transaction argument contains 8,019 trits (the length of a transaction without the transaction hash).
| Param | Type | Description |
| --- | --- | --- |
| transaction | Int8Array | Transaction trits |
This method takes an array of transaction trits, and checks its currentIndex field to validate whether it is the head transaction in a bundle.
To get a transaction's trits from the Tangle, use the getTrytes() method, then convert them to trits, using the trytesToTrits() method.
Returns: boolean - head - Whether the transaction is a head transaction.
Example
`js`
let head = Transaction.isHeadTransaction(transaction);
| Param | Type |
| --- | --- |
| lengthOrOffset | Int8Array |
Checks if given value is a valid transaction buffer length or offset.
| Param | Type | Description |
| --- | --- | --- |
| buffer | Int8Array | Transaction trytes |
Gets the signatureOrMessage field of all transactions in a bundle.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of address field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of value field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of obsoleteTag field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of issuanceTimestamp field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of currentIndex field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of lastIndex field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of bundle field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of trunkTransaction field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of branchTransaction field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of tag field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of attachmentTimestamp field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of attachmentTimestampLowerBound field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of attachmentTimestampUpperBound field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of tansactionNonce` field.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| buffer | Int8Array | | Transaction buffer. Buffer length must be a multiple of transaction length. |
| [offset] | Number | 0 | Transaction trit offset. It must be a multiple of transaction length. |
Returns a copy of transaction essence fields.