Class: Transaction
@nimiq/core / Transaction
Defined in: @nimiq/core/types/wasm/web.d.ts:2262
Transactions describe a transfer of value, usually from the sender to the recipient. However, transactions can also have no value, when they are used to signal a change in the staking contract.
Transactions can be used to create contracts, such as vesting contracts and HTLCs.
Transactions require a valid signature proof over their serialized content. Furthermore, transactions are only valid for 2 hours after their validity-start block height.
Constructors
Constructor
new Transaction(
sender,sender_type,sender_data,recipient,recipient_type,recipient_data,value,fee,flags,validity_start_height,network_id):Transaction
Defined in: @nimiq/core/types/wasm/web.d.ts:2325
Creates a new unsigned transaction that transfers value amount of luna (NIM's smallest unit)
from the sender to the recipient, where both sender and recipient can be any account type,
and custom extra data can be added to the transaction.
Basic transactions
If both the sender and recipient types are omitted or 0 and both data and flags are empty,
a smaller basic transaction is created.
Extended transactions
If no flags are given, but sender type is not basic (0) or data is set, an extended
transaction is created.
Contract creation transactions
To create a new vesting or HTLC contract, set flags to 0b1 and specify the contract
type as the recipient_type: 1 for vesting, 2 for HTLC. The data bytes must have
the correct format of contract creation data for the respective contract type.
Signaling transactions
To interact with the staking contract, signaling transaction are often used to not
transfer any value, but to simply signal a state change instead, such as changing one's
delegation from one validator to another. To create such a transaction, set flags to 0b10 and populate the data bytes accordingly.
The returned transaction is not yet signed. You can sign it e.g. with tx.sign(keyPair).
Throws when an account type is unknown, the numbers given for value and fee do not fit within a u64 or the networkId is unknown. Also throws when no data or recipient type is given for contract creation transactions, or no data is given for signaling transactions.
Parameters
sender
sender_type
number
sender_data
Uint8Array<ArrayBufferLike>
recipient
recipient_type
number
recipient_data
Uint8Array<ArrayBufferLike>
value
bigint
fee
bigint
flags
number
validity_start_height
number
network_id
number
Returns
Transaction
Properties
data
data:
Uint8Array
Defined in: @nimiq/core/types/wasm/web.d.ts:2373
The transaction's data as a byte array.
fee
readonlyfee:bigint
Defined in: @nimiq/core/types/wasm/web.d.ts:2377
The transaction's fee in luna (NIM's smallest unit).
feePerByte
readonlyfeePerByte:number
Defined in: @nimiq/core/types/wasm/web.d.ts:2381
The transaction's fee per byte in luna (NIM's smallest unit).
flags
readonlyflags:TransactionFlag
Defined in: @nimiq/core/types/wasm/web.d.ts:2387
The transaction's flags: 0b1 = contract creation, 0b10 = signaling.
Bit patterns outside the known variants collapse to None.
Inspect toPlain().flags for the raw value.
format
readonlyformat:TransactionFormat
Defined in: @nimiq/core/types/wasm/web.d.ts:2391
The transaction's TransactionFormat.
networkId
readonlynetworkId:number
Defined in: @nimiq/core/types/wasm/web.d.ts:2395
The transaction's network ID.
proof
proof:
Uint8Array
Defined in: @nimiq/core/types/wasm/web.d.ts:2399
The transaction's signature proof as a byte array.
recipient
readonlyrecipient:Address
Defined in: @nimiq/core/types/wasm/web.d.ts:2403
The transaction's recipient address.
recipientType
readonlyrecipientType:AccountType
Defined in: @nimiq/core/types/wasm/web.d.ts:2407
The transaction's recipient AccountType.
sender
readonlysender:Address
Defined in: @nimiq/core/types/wasm/web.d.ts:2411
The transaction's sender address.
senderData
readonlysenderData:Uint8Array
Defined in: @nimiq/core/types/wasm/web.d.ts:2415
The transaction's sender data as a byte array.
senderType
readonlysenderType:AccountType
Defined in: @nimiq/core/types/wasm/web.d.ts:2419
The transaction's sender AccountType.
serializedSize
readonlyserializedSize:number
Defined in: @nimiq/core/types/wasm/web.d.ts:2423
The transaction's byte size.
validityStartHeight
readonlyvalidityStartHeight:number
Defined in: @nimiq/core/types/wasm/web.d.ts:2427
The transaction's validity-start height. The transaction is valid for 2 hours after this block height.
value
readonlyvalue:bigint
Defined in: @nimiq/core/types/wasm/web.d.ts:2431
The transaction's value in luna (NIM's smallest unit).
Methods
__getClassname()
__getClassname():
string
Defined in: @nimiq/core/types/wasm/web.d.ts:2265
Returns
string
[dispose]()
[dispose]():
void
Defined in: @nimiq/core/types/wasm/web.d.ts:2264
Returns
void
free()
free():
void
Defined in: @nimiq/core/types/wasm/web.d.ts:2263
Returns
void
getContractCreationAddress()
getContractCreationAddress():
Address
Defined in: @nimiq/core/types/wasm/web.d.ts:2286
Returns the address of the contract that is created with this transaction.
Returns
hash()
hash():
string
Defined in: @nimiq/core/types/wasm/web.d.ts:2290
Computes the transaction's hash, which is used as its unique identifier on the blockchain.
Returns
string
isValidAt()
isValidAt(
block_height):boolean
Defined in: @nimiq/core/types/wasm/web.d.ts:2294
Tests if the transaction is valid at the specified block height.
Parameters
block_height
number
Returns
boolean
serialize()
serialize():
Uint8Array
Defined in: @nimiq/core/types/wasm/web.d.ts:2329
Serializes the transaction to a byte array.
Returns
Uint8Array
serializeContent()
serializeContent():
Uint8Array
Defined in: @nimiq/core/types/wasm/web.d.ts:2333
Serializes the transaction's content to be used for creating its signature.
Returns
Uint8Array
sign()
sign(
key_pair,inner_key_pair):void
Defined in: @nimiq/core/types/wasm/web.d.ts:2350
Signs the transaction with the provided key pair. Automatically determines the format of the signature proof required for the transaction.
For transactions to the staking contract (in-staking transactions), you can optionally provide an inner key pair that represents the staker or validator. This way the staker/validator and sender of a transaction can be different key pairs (addresses). If no inner key pair is provided, the outer key pair is used for both signatures.
Throws when the transaction's recipient data is not valid data for an incoming staking transaction, or when an incoming staking transaction is not sent from a basic account or a vesting contract.
Limitations
- HTLC redemption is not supported and will throw.
Parameters
key_pair
inner_key_pair
Returns
void
toHex()
toHex():
string
Defined in: @nimiq/core/types/wasm/web.d.ts:2354
Serializes the transaction into a HEX string.
Returns
string
toPlain()
toPlain(
genesis_block_number?,genesis_timestamp?):PlainTransaction
Defined in: @nimiq/core/types/wasm/web.d.ts:2358
Creates a JSON-compatible plain object representing the transaction.
Parameters
genesis_block_number?
number
genesis_timestamp?
bigint
Returns
verify()
verify(
protocol_version,network_id?):void
Defined in: @nimiq/core/types/wasm/web.d.ts:2369
Verifies that a transaction has valid properties and a valid signature proof for the
provided protocol_version.
Optionally checks if the transaction is valid on the provided network.
Throws with any transaction validity error. Returns without exception if the transaction is valid.
A protocol_version of 0 is accepted for backwards-compatible pre-upgrade validation.
Throws when the given networkId is unknown.
Parameters
protocol_version
number
network_id?
number
Returns
void
deserialize()
staticdeserialize(bytes):Transaction
Defined in: @nimiq/core/types/wasm/web.d.ts:2269
Deserializes a transaction from a byte array.
Parameters
bytes
Uint8Array
Returns
Transaction
fromAny()
staticfromAny(tx):Transaction
Defined in: @nimiq/core/types/wasm/web.d.ts:2276
Parses a transaction from a Transaction instance, a plain object, a hex string representation, or a byte array.
Throws when a transaction cannot be parsed from the argument.
Parameters
tx
string | PlainTransaction | Uint8Array<ArrayBufferLike> | Transaction
Returns
Transaction
fromPlain()
staticfromPlain(plain):Transaction
Defined in: @nimiq/core/types/wasm/web.d.ts:2282
Parses a transaction from a plain object.
Throws when a transaction cannot be parsed from the argument.
Parameters
plain
Returns
Transaction