# Adding complex operations

Complex usage of ITransaction interface allows to:

  • manually initialize transaction object with some blockchain properties (like TaPoS)
  • use provided operation factory classes which encapsulate blockchain complexity (this part operates on any transaction object - regardless of way how you obtained it)

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".

Here we utilize WitnessSetPropertiesOperation class to build a complex operation using simple interface:

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_operation: {
    owner: 'owner',
    props: {
      key: '02472d6eb6d691b6de8b103b51ebdf4e128a523946d8cd03d6ded91b1497ee2e83',
      url: '1368747470733a2f2f6578616d706c652e636f6d'
    },
    extensions: []
  }
}

TBA

As usually, the "push operation" 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 "push operation" method returns an instance of ITransaction 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.