The ITransaction interface provides methods for building, signing, and managing blockchain transactions. It supports both simple inline operations and complex operation builders.
Creating transactions
Transactions are created using WAX instance methods:
// Offline: Manual TAPOS
const tx = wax . createTransactionWithTaPoS ( headBlockId , "+1m" );
// Online: Automatic TAPOS
const tx = await chain . createTransaction ( "+5m" );
// From existing JSON
const tx = wax . createTransactionFromJson ( apiTxJson );
// From protobuf
const tx = wax . createTransactionFromProto ( protoTx );
Adding operations
pushOperation
Pushes an operation to the transaction. Supports both inline operations and complex operation builders.
pushOperation ( op : operation | OperationBase ): this ;
op
operation | OperationBase
required
Operation to add. Can be:
Inline operation object
Complex operation class instance (BlogPostOperation, ReplyOperation, etc.)
Returns the transaction instance for method chaining
Inline operation example
tx . pushOperation ({
vote: {
voter: "alice" ,
author: "bob" ,
permlink: "example-post" ,
weight: 10000
}
});
Complex operation example
import { BlogPostOperation } from '@hiveio/wax' ;
tx . pushOperation ( new BlogPostOperation ({
author: "alice" ,
category: "hive-174695" ,
title: "My awesome post" ,
body: "This is the post content" ,
permlink: "my-awesome-post" ,
tags: [ "blog" , "travel" ],
description: "A post about my travels"
}));
Transaction properties
Generates the transaction ID (HF26 serialization).
get id (): TTransactionId ;
Transaction ID in hex form (20 bytes)
legacy_id
Generates the transaction ID (legacy serialization).
get legacy_id (): TTransactionId ;
sigDigest
Generates the digest for signing (HF26 serialization).
get sigDigest (): THexString ;
Transaction digest in hex form for signature generation
legacy_sigDigest
Generates the digest for signing (legacy serialization).
get legacy_sigDigest (): THexString ;
transaction
Returns the underlying protobuf transaction object.
get transaction (): transaction ;
impactedAccounts
Retrieves account names impacted by the transaction.
get impactedAccounts (): Set < TAccountName > ;
Set of account names impacted by all operations in the transaction
signatureKeys
Returns public keys from the transaction signatures.
get signatureKeys (): Array < THexString > ;
List of all public keys that were used to sign the transaction
requiredAuthorities
Returns required authority accounts from the transaction.
get requiredAuthorities (): TTransactionRequiredAuthorities ;
TTransactionRequiredAuthorities
TTransactionRequiredAuthorities
Accounts requiring posting authority
Accounts requiring active authority
Accounts requiring owner authority
Retrieves transaction binary view packed AST data.
get binaryViewMetadata (): IBinaryViewOutputData ;
Binary representation in hex
AST node structure with offsets
Signing
addSignature
Adds a signature to the transaction.
addSignature ( signature : THexString ): this ;
Signature in hexadecimal format
Returns the transaction instance for method chaining
Usage with signature providers
import { createHiveChain } from '@hiveio/wax' ;
import { createBeekeeperSigner } from '@hiveio/wax-signers-beekeeper' ;
const chain = await createHiveChain ();
const signer = await createBeekeeperSigner ({
/* beekeeper config */
});
// Create transaction
const tx = await chain . createTransaction ();
tx . pushOperation ({
vote: {
voter: "alice" ,
author: "bob" ,
permlink: "example-post" ,
weight: 10000
}
});
// Sign with provider
const signature = await signer . signTransaction ( tx . sigDigest );
tx . addSignature ( signature );
// Broadcast
await chain . api . network_broadcast_api . broadcast_transaction ({
trx: tx . toApiJson ()
});
isSigned
Checks if the transaction has been signed.
Returns true if at least one signature is present
Validation
validate
Validates the current transaction.
Throws WaxError on validation error.
Usage example
try {
tx . validate ();
console . log ( 'Transaction is valid' );
} catch ( error ) {
console . error ( 'Validation failed:' , error . message );
}
Serialization
toApi
Converts the transaction to Hive API-form string (HF26).
Transaction in Hive API-form JSON string
toApiJson
Converts the transaction to Hive API-form JSON object (HF26).
toApiJson (): ApiTransaction ;
Transaction in Hive API-form JSON object
toLegacyApi
Converts the transaction to legacy Hive API-form string.
Note: Legacy form is deprecated. It produces larger binary serialization output and is more error-prone.
toString
Converts the transaction to protobuf JSON string.
Converts the transaction to HF26 binary form.
toBinaryForm ( stripToUnsignedTransaction ?: boolean ): THexString ;
stripToUnsignedTransaction
Optional flag to strip signatures from the binary output
Transaction in hexadecimal binary form
Encryption
startEncrypt
Starts encryption chain for operations.
startEncrypt (
mainEncryptionKey : TPublicKey ,
otherEncryptionKey ?: TPublicKey
): this & IEncryptingTransaction < this > ;
First key to encrypt operations
Optional second key to encrypt operations
this & IEncryptingTransaction<this>
Returns the transaction with encryption capabilities
Supported encrypted fields
body in comment operation
json in custom_json operation
memo in transfer operation
memo in transfer_to_savings operation
memo in transfer_from_savings operation
memo in recurrent_transfer operation
Usage example
const tx = await chain . createTransaction ();
tx . startEncrypt ( myPublicKey )
. pushOperation ({
transfer: {
from: "alice" ,
to: "bob" ,
amount: chain . hiveCoins ( 10 ),
memo: "This will be encrypted"
}
})
. stopEncrypt ();
// Sign with encryption provider
const signature = await encryptionProvider . signTransaction ( tx );
tx . addSignature ( signature );
stopEncrypt
Stops the encryption chain.
Returns the transaction instance
Note: This call is optional if you’re not pushing any more unencrypted operations.
decrypt
Decrypts all underlying encrypted operations.
decrypt ( wallet : ISignatureProvider ): transaction ;
wallet
ISignatureProvider
required
Unlocked wallet with decryption keys
Protobuf transaction object with decrypted operations
TypeScript types
transaction (protobuf)
interface transaction {
ref_block_num : number ;
ref_block_prefix : number ;
expiration : string ;
operations : Array < operation >;
extensions : Array < any >;
signatures : Array < string >;
}
ApiTransaction
interface ApiTransaction {
ref_block_num : number ;
ref_block_prefix : number ;
expiration : string ;
operations : Array < ApiOperation >;
extensions : object [];
signatures : string [];
}
interface ApiOperation {
type : string ;
value : Record < string , any >;
}
TTransactionRequiredAuthorities
type TTransactionRequiredAuthorities = {
posting : Set < string >;
active : Set < string >;
owner : Set < string >;
other : Array < authority >;
};
Complete example
import { createHiveChain } from '@hiveio/wax' ;
import { BlogPostOperation } from '@hiveio/wax' ;
import { createBeekeeperSigner } from '@hiveio/wax-signers-beekeeper' ;
// Initialize
const chain = await createHiveChain ();
const signer = await createBeekeeperSigner ({ /* config */ });
// Create transaction
const tx = await chain . createTransaction ( "+5m" );
// Add blog post
tx . pushOperation ( new BlogPostOperation ({
author: "alice" ,
category: "hive-174695" ,
title: "My First Post" ,
body: "Hello Hive!" ,
permlink: "my-first-post" ,
tags: [ "introduction" , "blog" ],
description: "My introduction to Hive"
}));
// Validate
tx . validate ();
// Check required authorities
console . log ( 'Required authorities:' , tx . requiredAuthorities );
// Sign
const signature = await signer . signTransaction ( tx . sigDigest );
tx . addSignature ( signature );
// Verify signed
console . log ( 'Is signed:' , tx . isSigned ());
console . log ( 'Transaction ID:' , tx . id );
// Broadcast
try {
await chain . api . network_broadcast_api . broadcast_transaction ({
trx: tx . toApiJson ()
});
console . log ( 'Transaction broadcasted successfully!' );
} catch ( error ) {
console . error ( 'Broadcast failed:' , error );
}
See also