# Adding complex operations

Complex usage of Transaction interface allows to:

  • manually initialize transaction object with some blockchain properties (like TaPoS) - you can achieve it by using createTransactionWithTaPoS method.
  • use provided operation factory classes which encapsulate blockchain complexity (this part operates on any transaction object - regardless of way how you obtained it: by using createTransactionWithTaPoS or createTransaction method).

Below is a complete example of a blockchain operation, requiring explicit serialization of input data to properly build final operation. All such steps require complex knowledge of blockchain internals and have been adopted to "regular programming steps" by using provided WitnessSetPropertiesOperation class.

import { createHiveChain, WitnessSetPropertiesOperation } from '@hiveio/wax';

// Initialize chain
const chain = await createHiveChain();

const { publicKey1 } = globalThis.snippetsBeekeeperData;

// Initialize a transaction object
const tx = await chain.createTransaction();

// Build operation
tx.pushOperation(new WitnessSetPropertiesOperation({
  owner: 'owner',
  witnessSigningKey: publicKey1,
  url: 'https://example.com'

}));

// Get a transaction object holding all operations and transaction TAPOS & expiration data, but transaction is **not signed yet**
const builtTransaction = tx.transaction;

console.log(builtTransaction.operations[0]); // Witness set properties operation
{
  witness_set_properties: {
    owner: 'owner',
    props: {
      key: '02472d6eb6d691b6de8b103b51ebdf4e128a523946d8cd03d6ded91b1497ee2e83',
      url: '1368747470733a2f2f6578616d706c652e636f6d'
    },
    extensions: []
  }
}

As usually, the pushOperation method allows you to push any operation (regadless to complexity related to given blockchain scenario, being encapsulated by used operation class). At the end, the pushOperation method returns an instance of Transaction interface, on which you can later perform operations related to the transaction. It nicely reuses well known scheme: Call-chain

More complex information about pushOperation are presented in subsequent chapters.