Documentation / @cashconnect-js/core / primitives/transaction
TransactionFromArgs
type TransactionFromArgs = Parameters<typeof from>[0];Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:530
Transaction
Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:160
Transaction Primitive.
Example
// Import our primitives.
import { Transaction } from '@libcash/primitives';
// Instantiate primitive from Transaction Hex.
const transaction = Transaction.from('transactionHex');
// Output Transaction Information.
console.log(transaction.getVersion());
console.log(transaction.getLocktime());
console.log(transaction.getInputs());
console.log(transaction.getOutputs());
// Output the Transaction Hash.
console.log(transaction.toHash().toHex());Extends
BaseTransaction
Methods
from()
static from(transaction): Transaction;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:177
Instantiates a transaction from either:
- Transaction bytecode
- Transaction bytecode (in hexadecimal format)
Parameters
| Parameter | Type | Description |
|---|---|---|
transaction | | string | Uint8Array<ArrayBufferLike> | TransactionBCH | Transaction | The transaction in one of the above formats. |
Returns
The created Transaction Primitive.
Throws
If transaction data cannot be decoded.
fromBytes()
static fromBytes(bytes): Transaction;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:204
Create a Transaction Primitive from the given byte data.
Parameters
| Parameter | Type | Description |
|---|---|---|
bytes | Uint8Array | The raw byte data of the transaction. |
Returns
The created Transaction Primitive.
Throws
If transaction data cannot be decoded.
fromHex()
static fromHex(hex): Transaction;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:226
Create a Transaction Primitive from the given byte data encoded as hexadecimal string.
Parameters
| Parameter | Type | Description |
|---|---|---|
hex | string | The raw byte data (encoded as hexadecimal string) of the transaction. |
Returns
The created Transaction Primitive.
Throws
If transaction cannot be decoded.
fromRaw()
static fromRaw(transaction): Transaction;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:240
Create a Transaction Primitive from LibAuth's TransactionBCH type.
Parameters
| Parameter | Type | Description |
|---|---|---|
transaction | TransactionBCH | The transaction object (as per LibAuth). |
Returns
The created Transaction Primitive.
Remarks
This method is UNSAFE and MUST only be used where input is already verified or trusted.
isValid()
static isValid(transaction): boolean;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:251
Validates the structure of a transaction.
Parameters
| Parameter | Type | Description |
|---|---|---|
transaction | string | Uint8Array<ArrayBufferLike> | The transaction (as hex or bytes). |
Returns
boolean
boolean indicating whether the transaction structure is valid.
toRaw()
toRaw(): TransactionBCH;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:265
Converts transaction to a raw object representation.
Returns
TransactionBCH
A TransactionBCH LibAuth object.
toBytes()
toBytes(): Uint8Array;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:24
Serializes the transaction to a byte array.
Returns
Uint8Array
The transaction serialized as a Uint8Array
Inherited from
BaseTransaction.toBytestoHex()
toHex(): string;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:34
Serializes the transaction to a byte array (represented as a hex string).
Returns
string
The transaction serialized in hex
Inherited from
BaseTransaction.toHextoHash()
toHash(): TransactionHash;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:44
Hashes the transaction and returns a TransactionHash primitive.
Returns
The transaction hash primitive.
Inherited from
BaseTransaction.toHashtoHashHex()
toHashHex(): string;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:52
Hashes the transaction and returns the hash as hexadecimal.
Returns
string
The transaction hash hex.
Inherited from
BaseTransaction.toHashHextoHashBytes()
toHashBytes(): Uint8Array;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:60
Hashes the transaction and returns the hash as a Uint8Array.
Returns
Uint8Array
The transaction hash bytes.
Inherited from
BaseTransaction.toHashBytesgetVersion()
getVersion(): number;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:71
Experimental
Gets the version for this transaction.
Returns
number
The version of this transaction
Inherited from
BaseTransaction.getVersiongetInputs()
getInputs(): Input[];Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:82
Experimental
Gets the inputs in this transaction.
Returns
Input[]
The inputs in this transaction
Inherited from
BaseTransaction.getInputsgetOutputs()
getOutputs(): Output[];Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:93
Experimental
Gets the outputs in this transaction.
Returns
Output[]
The outputs in this transaction
Inherited from
BaseTransaction.getOutputsgetLocktime()
getLocktime(): number;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:104
Experimental
Gets the locktime for this transaction.
Returns
number
The locktime of this transaction
Inherited from
BaseTransaction.getLocktimeisCoinbase()
isCoinbase(): boolean;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:117
Experimental
Checks whether this transaction is a Coinbase Transaction.
Returns
boolean
True if this is a Coinbase Transaction
Remarks
UNTESTED
Inherited from
BaseTransaction.isCoinbaseTransactionResolved
Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:270
Extends
BaseTransaction
Methods
from()
static from(transaction, sourceOutputs): TransactionResolved;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:293
Instantiates a transaction from either:
- Transaction bytecode
- Transaction bytecode (in hexadecimal format)
Parameters
| Parameter | Type | Description |
|---|---|---|
transaction | string | Uint8Array<ArrayBufferLike> | The transaction in one of the above formats. |
sourceOutputs | any[] | - |
Returns
The created Transaction Primitive.
Throws
If transaction data cannot be decoded.
fromBytes()
static fromBytes(bytes, sourceOutputs): TransactionResolved;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:311
Create a Transaction Primitive from the given byte data.
Parameters
| Parameter | Type | Description |
|---|---|---|
bytes | Uint8Array | The raw byte data of the transaction. |
sourceOutputs | any[] | - |
Returns
The created Transaction Primitive.
Throws
If transaction data cannot be decoded.
fromHex()
static fromHex(hex, sourceOutputs): TransactionResolved;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:333
Create a Transaction Primitive from the given byte data encoded as hexadecimal string.
Parameters
| Parameter | Type | Description |
|---|---|---|
hex | string | The raw byte data (encoded as hexadecimal string) of the transaction. |
sourceOutputs | any[] | - |
Returns
The created Transaction Primitive.
Throws
If transaction cannot be decoded.
fromRaw()
static fromRaw(resolvedTransaction): TransactionResolved;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:347
Create a Transaction Primitive from LibAuth's TransactionBCH type.
Parameters
| Parameter | Type | Description |
|---|---|---|
resolvedTransaction | ResolvedTransactionCommon | The transaction object (as per LibAuth). |
Returns
The created Transaction Primitive.
Remarks
This method is UNSAFE and MUST only be used where input is already verified or trusted.
isValid()
static isValid(transaction, sourceOutputs): boolean;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:361
Validates the structure of a transaction.
Parameters
| Parameter | Type | Description |
|---|---|---|
transaction | string | Uint8Array<ArrayBufferLike> | The transaction (as hex or bytes). |
sourceOutputs | any[] | - |
Returns
boolean
boolean indicating whether the transaction structure is valid.
toRaw()
toRaw(): object;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:374
Returns
object
| Name | Type | Defined in |
|---|---|---|
transaction | TransactionBCH | cashconnect-js/packages/core/src/primitives/transaction.ts:376 |
sourceOutputs | any[] | cashconnect-js/packages/core/src/primitives/transaction.ts:377 |
toBytes()
toBytes(): Uint8Array;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:24
Serializes the transaction to a byte array.
Returns
Uint8Array
The transaction serialized as a Uint8Array
Inherited from
BaseTransaction.toBytestoHex()
toHex(): string;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:34
Serializes the transaction to a byte array (represented as a hex string).
Returns
string
The transaction serialized in hex
Inherited from
BaseTransaction.toHextoHash()
toHash(): TransactionHash;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:44
Hashes the transaction and returns a TransactionHash primitive.
Returns
The transaction hash primitive.
Inherited from
BaseTransaction.toHashtoHashHex()
toHashHex(): string;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:52
Hashes the transaction and returns the hash as hexadecimal.
Returns
string
The transaction hash hex.
Inherited from
BaseTransaction.toHashHextoHashBytes()
toHashBytes(): Uint8Array;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:60
Hashes the transaction and returns the hash as a Uint8Array.
Returns
Uint8Array
The transaction hash bytes.
Inherited from
BaseTransaction.toHashBytesgetVersion()
getVersion(): number;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:71
Experimental
Gets the version for this transaction.
Returns
number
The version of this transaction
Inherited from
BaseTransaction.getVersiongetInputs()
getInputs(): Input[];Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:82
Experimental
Gets the inputs in this transaction.
Returns
Input[]
The inputs in this transaction
Inherited from
BaseTransaction.getInputsgetOutputs()
getOutputs(): Output[];Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:93
Experimental
Gets the outputs in this transaction.
Returns
Output[]
The outputs in this transaction
Inherited from
BaseTransaction.getOutputsgetLocktime()
getLocktime(): number;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:104
Experimental
Gets the locktime for this transaction.
Returns
number
The locktime of this transaction
Inherited from
BaseTransaction.getLocktimeisCoinbase()
isCoinbase(): boolean;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:117
Experimental
Checks whether this transaction is a Coinbase Transaction.
Returns
boolean
True if this is a Coinbase Transaction
Remarks
UNTESTED
Inherited from
BaseTransaction.isCoinbaseTransactionHash
Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:385
Transaction Hash Primitive.
Methods
from()
static from(hash): TransactionHash;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:404
Instantiates a TransactionHash from either the Hash Hex or Hash Bytes.
Parameters
| Parameter | Type | Description |
|---|---|---|
hash | string | Uint8Array<ArrayBufferLike> | The Transaction Hash as either hex or bytes. |
Returns
The created Public Key Primitive.
Throws
If the hash is invalid.
fromBytes()
static fromBytes(bytes): TransactionHash;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:419
Instantiates TransactionHash from Hash Bytes.
Parameters
| Parameter | Type | Description |
|---|---|---|
bytes | Uint8Array | The hash as bytes. |
Returns
Instance of TransactionHash.
Throws
If hash is invalid.
fromHex()
static fromHex(hex): TransactionHash;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:439
Instantiates TransactionHash from a hex string.
Parameters
| Parameter | Type | Description |
|---|---|---|
hex | string | {string} The hex string. |
Returns
Instance of TransactionHash.
Throws
If hex is invalid.
fromTransaction()
static fromTransaction(transaction): TransactionHash;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:453
Instantiates a TransactionHash from either the Transaction Hex or Transaction Hash.
Parameters
| Parameter | Type | Description |
|---|---|---|
transaction | string | Uint8Array<ArrayBufferLike> | The Transaction as either hex or bytes. |
Returns
The created Public Key Primitive.
Throws
If the public key cannot be decoded.
fromTransactionBytes()
static fromTransactionBytes(transactionBytes): TransactionHash;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:466
Instantiates TransactionHash from a Transaction's bytes.
Parameters
| Parameter | Type | Description |
|---|---|---|
transactionBytes | Uint8Array | {Uint8Array} The Transaction's bytes. |
Returns
Instance of TransactionHash.
fromTransactionHex()
static fromTransactionHex(transactionHex): TransactionHash;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:483
Instantiates TransactionHash from a Transaction's bytes in hex.
Parameters
| Parameter | Type | Description |
|---|---|---|
transactionHex | string | {Uint8Array} The Transaction's bytes in hex. |
Returns
Instance of TransactionHash.
Throws
If hex is invalid.
fromRaw()
static fromRaw(bytes): TransactionHash;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:497
Creates an instance from serialized data.
Parameters
| Parameter | Type | Description |
|---|---|---|
bytes | Uint8Array | Serialized Primitive Data |
Returns
A new instance of this primitive.
Remarks
This method is UNSAFE and MUST only be used where input is already verified or trusted.
toHex()
toHex(): string;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:506
Returns transaction hash as a hex string.
Returns
string
Hex string of the Transaction Hash.
toBytes()
toBytes(): Uint8Array;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:515
Returns transaction hash as a Uint8Array.
Returns
Uint8Array
Uint8Array of the Transaction Hash.
toRaw()
toRaw(): Uint8Array<ArrayBufferLike>;Defined in: cashconnect-js/packages/core/src/primitives/transaction.ts:524
Converts this primitive to a serializable representation.
Returns
Uint8Array<ArrayBufferLike>
Serialzied primitive data.