#
Advanced usage
If you want to use the advanced features of the ITransaction
interface you can initalize it using dedicated methods:
#
Initialization with explicit TaPoS and expiration time
Creating transaction with TaPoS can be useful for cases when you would like to perform batch operations without any access to remote Hive API calls.
Due to long TaPoS lifespan (near to 64000 blocks, so it really targets to the c.a. 3 hours), you can easily receive TaPoS data (reference block-id) once from blockchain and next reuse it in your code generating massive transactions, to finally sign and broadcast them:
Test it yourself: src/typescript/transaction/example-usage/advanced-usage/explicit-data-initialization.ts
import { createHiveChain, createWaxFoundation, IWaxBaseInterface } from '@hiveio/wax';
const chain = await createHiveChain();
// We use IWaxBaseInterface here to enforce lack of any network activity.
const base: IWaxBaseInterface = chain;
/** `createTransactionWithTaPoS` can be useful for cases
* when you would like to perform a lot of massive operations
* without any access to remote Hive API calls.
* Due to long TAPOS lifespan (near to 64000 blocks,
* so it really targets to the c.a. 3 hours), you can easily
* once receive TAPOS data (reference block-id) from blockchain
* and next reuse it in your code generating massive transactions,
* to finally sign and broadcast them.
*/
const { head_block_id } = await chain.api.database_api.get_dynamic_global_properties({});
/// here comes your massive transaction generation code:
base.createTransactionWithTaPoS(head_block_id, '+10m');
/// Add some operations here
/// to finally sign and broadcast
TBA
#
Initialization from hive API-JSON form
This can be useful for analyzing transactions retrieved from the API or restored previously from the API form.
Test it yourself: src/typescript/transaction/example-usage/advanced-usage/api-form-initialization.ts
import { createHiveChain, IWaxBaseInterface } from '@hiveio/wax';
const chain = await createHiveChain();
// We use IWaxBaseInterface here to enforce lack of any network activity.
const base: IWaxBaseInterface = chain;
/**
* This creation method is useful for cases,
* when already confirmed blockchain transaction is about to
* analyzed using ITransaction functions
* such as providing signatureKeys or transactoin ID.
*/
// Fetch block data from Hive API.
const { block } = await chain.api.block_api.get_block({ block_num: 5000000 });
// Converts Hive API-form transaction in JSON form to our transaction.
base.createTransactionFromJson(block!.transactions[0]);
TBA
#
Initialize from protobuf transaction
This can be useful for analyzing transactions restored previously from the protobuf form.
Test it yourself: src/typescript/transaction/example-usage/advanced-usage/protobuf-transaction-initialization.ts
import { createWaxFoundation, transaction } from '@hiveio/wax';
const wax = await createWaxFoundation();
/**
* This creation method is dedicated to usecases, when
* protobuf transaction object is available for further use.
* All other actions provided by ITransaction interface are
* very common to the case specifc to API-JSON interaction.
*/
const tx: transaction = {
ref_block_num: 34559,
ref_block_prefix: 1271006404,
expiration: '2021-12-13T11:31:33',
operations: [],
extensions: [],
signatures: []
};
// Constructs a new Transaction object with ready protobuf transaction.
wax.createTransactionFromProto(tx);
TBA