Transactions

Transaction utility functions are defined in @liskhq/lisk-transactions. The functionalities can be accessed through package @liskhq/lisk-transactions, @liskhq/lisk-client or lisk-sdk.

Installation

$ npm install @liskhq/lisk-transactions

Upgrade

To perform an upgrade, execute the following command:

npm update @liskhq/lisk-transactions

Signing transactions

signTransaction

Signs a transaction with given networkIdentifier and passphrase. Returns a transaction object with a signature.

signTransaction(
  // schema defined in custom asset to be signed
  assetSchema: Schema,
  // transaction object in JavaScript object format
  transactionObject: Record<string, unknown>,
  networkIdentifier: Buffer,
  passphrase: string,
): Record<string, unknown>;

signMultiSignatureTransaction

Signs a transaction with given passphrase as a multi signature account. This method can be used for signing registerMultisignatureGroup by setting includeSenderSignature to true.

signMultiSignatureTransaction(
  // schema defined in the custom asset to be signed
  assetSchema: Schema,
  // transaction object in JavaScript object format
  transactionObject: Record<string, unknown>,
  networkIdentifier: Buffer,
  passphrase: string,
  // keys which correspond to the sender account of the transaction
  keys: {
    mandatoryKeys: Buffer[],
    optionalKeys: Buffer[],
  },
  // By setting true, signature corresponds to the sender public key will also be included in the signatures
  // This should be used for registerMultisignatureGroup transaction
  includeSenderSignature = false,
): Record<string, unknown>

getBytes

Validates the transaction against the asset schema and returns transaction bytes.

getBytes (
  // schema defined in custom asset
  assetSchema: Schema,
  // transaction object in JavaScript object format
  transactionObject: Record<string, unknown>,
): Buffer;

getSigningBytes

Validates the transaction against the asset schema and returns transaction bytes for signing.

getSigningBytes (
  // schema defined in custom asset to be signed
  assetSchema: Schema,
  // transaction object in JavaScript object format
  transactionObject: Record<string, unknown>,
): Buffer;

Changing between formats

convertBeddowsToLSK

This converts amounts in Beddows, (the smallest denomination) to the amounts in one LSK.

Syntax

convertBeddowsToLSK(amount)

Parameters

amount: string decimal representation of amount to be converted.

Return value

string: Amount in LSK.

Examples

transactions.convertBeddowsToLSK('100000'); // '0.001'

convertLSKToBeddows

This converts the amounts in LSK to the amounts in Beddows, (the smallest denomination).

Syntax

convertLSKToBeddows(amount)

Parameters

amount: string decimal representation of amount to be converted.

Return value

string: Amount in Beddows.

Examples

transactions.convertLSKToBeddows('0.001'); // '100000'

Validating transactions

validateTransaction

Statically validates the transaction object input using the schema.

validateTransaction(
  // schema defined in custom asset to be signed
  assetSchema: Schema,
  // transaction object in JavaScript object format
  transactionObject: Record<string, unknown>,
): LiskValidationError | Error | undefined;

Calculating the minimum fee for a transaction

computeMinFee

Returns the minimal fee for a transaction.

computeMinFee(
// schema defined in custom asset to be signed
  assetSchema: Schema,
  // transaction object in JavaScript object format
  transactionObject: Record<string, unknown>,
  options?: {
    minFeePerByte: number,
    baseFees: { moduleID: number, assetID: number, baseFee: number}[],
    numberOfSignatures: number,
  }
): bigint