Class Transaction
Hierarchy
- Transaction
- Transaction
Index
Constructors
Properties
Methods
Constructors
constructor
Create a Transaction from proto-generated transaction data
Parameters
Optionaldata: ITransactionProto transaction data (from node or local build)
Returns Transaction
Properties
Block
Transaction Block.
GasLimit
Transaction GasLimit.
GasMultiplier
Transaction GasMultiplier.
OptionalRawData
Transaction RawData.
Receipts
Transaction Receipts.
Result
Transaction Result.
ResultCode
Transaction ResultCode.
Signature
Transaction Signature.
Methods
getHash
getHashBytes
getTotalFee
Get total fee (KAppFee + BandwidthFee) Returns the combined fee for the transaction in smallest KLV units
Returns bigint
Total fee amount in KLV smallest units (1 KLV = 1,000,000 units)
isSigned
Check if transaction is signed Verifies whether the transaction has been signed and is ready for broadcast
Returns boolean
true if transaction has at least one signature, false otherwise
sign
Sign the transaction with a private key Signs the transaction hash (blake2b of RawData)
Parameters
- privateKey: PrivateKey
Private key to sign with
Returns Promise<Transaction>
This transaction instance with signature added
- privateKey: PrivateKey
toBytes
toHex
Get proto bytes as hex string Useful for broadcasting to node via HTTP or storing in databases
Returns string
Hex encoded proto bytes (without 0x prefix)
toJSON
Converts this Transaction to JSON.
Returns { [k: string]: unknown }
JSON object
Staticcreate
Creates a new Transaction instance using the specified properties.
Parameters
Optionalproperties: ITransactionProperties to set
Returns Transaction
Transaction instance
Staticdecode
Decodes a Transaction message from the specified reader or buffer.
Parameters
- reader: Uint8Array<ArrayBufferLike> | Reader
Reader or buffer to decode from
Optionallength: numberMessage length if known beforehand
Returns Transaction
Transaction
- reader: Uint8Array<ArrayBufferLike> | Reader
StaticdecodeDelimited
Staticencode
Encodes the specified Transaction message. Does not implicitly verify messages.
Parameters
- message: ITransaction
Transaction message or plain object to encode
Optionalwriter: WriterWriter to encode to
Returns Writer
Writer
- message: ITransaction
StaticencodeDelimited
Encodes the specified Transaction message, length delimited. Does not implicitly verify messages.
Parameters
- message: ITransaction
Transaction message or plain object to encode
Optionalwriter: WriterWriter to encode to
Returns Writer
Writer
- message: ITransaction
StaticfromBytes
Create a Transaction from raw proto bytes Decodes protobuf bytes back into a Transaction object
Parameters
- bytes: Uint8Array
Proto-encoded transaction bytes
Returns Transaction
Transaction instance
- bytes: Uint8Array
StaticfromHex
Create a Transaction from hex-encoded proto bytes Decodes a hex string back into a Transaction object
Parameters
- hex: string
Hex string of proto-encoded transaction (with or without 0x prefix)
Returns Transaction
Transaction instance
- hex: string
StaticfromObject
Create a Transaction from a plain JSON object (from API) Properly converts base64 strings to Uint8Array for proto fields. This is typically used when receiving transaction data from the node's API.
Parameters
- obj: { [k: string]: unknown }
Plain object with base64-encoded byte fields
Returns Transaction
Transaction instance
Example
// Response from node's /transaction/build endpoint
const response = await fetch('/transaction/build', {
method: 'POST',
body: JSON.stringify(buildRequest)
})
const data = await response.json()
// Convert API response to Transaction
const tx = Transaction.fromObject(data.result)
// Sign and broadcast
await tx.sign(privateKey)
await provider.sendRawTransaction(tx.toHex())- obj: { [k: string]: unknown }
StaticfromTransaction
Create a new Transaction from an existing Transaction Creates a deep copy of the transaction
Parameters
- tx: Transaction
Existing Transaction instance
Returns Transaction
New Transaction instance
- tx: Transaction
StaticgetTypeUrl
Gets the default type url for Transaction
Parameters
OptionaltypeUrlPrefix: stringyour custom typeUrlPrefix(default "type.googleapis.com")
Returns string
The default type url
StatictoObject
Creates a plain object from a Transaction message. Also converts values to other types if specified.
Parameters
- message: Transaction
Transaction
Optionaloptions: IConversionOptionsConversion options
Returns { [k: string]: any }
Plain object
- message: Transaction
Staticverify
Verifies a Transaction message.
Parameters
- message: { [k: string]: any }
Plain object to verify
Returns null | string
nullif valid, otherwise the reason why it is not- message: { [k: string]: any }
Transaction class representing a Klever blockchain transaction Extends the protobuf Transaction class with convenience methods
This class wraps the proto-generated Transaction and provides:
This is a pure data class - no network dependencies. Use provider.sendRawTransaction(tx.toHex()) to broadcast.