#
Finalization
When the work with the transaction is ready, you now need to decide what you want to do with it next.
#
Conversion to api form
The simple toApi
method returns the transaction in the Hive API-JSON form:
import { createHiveChain } from '@hiveio/wax';
// Initialize hive chain interface
const chain = await createHiveChain();
// Initialize a transaction object
const tx = await chain.createTransaction();
// Declare example operation
const operation = {
vote_operation: {
voter: "voter",
author: "test-author",
permlink: "test-permlink",
weight: 2200
}
};
// Push operation into the transction
tx.pushOperation(operation);
// Log to the console the transaction which is **not signed yet** in the api form
console.log(tx.toApi());
// broadcast the transaction
// Uncomment the following line to broadcast the transaction to the mainnet
// (this will most likely fail due to transaction not being signed):
// await chain.broadcast(tx);
{
"ref_block_num": 1960,
"ref_block_prefix": 3915120327,
"expiration": "2023-11-09T21:51:27",
"operations": [
{
"type": "vote_operation",
"value": {
"voter": "voter",
"author": "test-author",
"permlink": "test-permlink",
"weight": 2200
}
}
]
}
TBA
You can also represent your transaction in the API form, with your signature added to the internal signatures array (it will also apply the transaction expiration time):
import { createHiveChain } from '@hiveio/wax';
// Initialize hive chain interface
const chain = await createHiveChain();
// Initialize a transaction object
const tx = await chain.createTransaction();
// Declare example operation
const operation = {
vote_operation: {
voter: "voter",
author: "author",
permlink: "test-permlink",
weight: 2200
}
};
// Push operation into the transction
tx.pushOperation(operation);
// Supplement a transaction with an externally generated signature.
tx.addSignature('deadc0de');
console.log(tx.toApi());
{
"ref_block_num": 1960,
"ref_block_prefix": 3915120327,
"expiration": "2023-11-09T21:51:27",
"operations": [
{
"type": "vote_operation",
"value": {
"voter": "voter",
"author": "author",
"permlink": "test-permlink",
"weight": 2200
}
}
],
"signatures": [
"signature..."
]
}
TBA
Multiple signatures
Also remember that you can add more than one signature while signing your transaction.
If you want to sign your transaction in traditional way and return it in the API form, you can use this sample (it will also apply the transaction expiration time):
import { createHiveChain } from '@hiveio/wax';
// Initialize hive chain interface
const chain = await createHiveChain();
const { signer1 } = globalThis.snippetsBeekeeperData;
// Initialize a transaction object
const tx = await chain.createTransaction();
// Declare example operation
const operation = {
vote_operation: {
voter: "voter",
author: "author",
permlink: "test-permlink",
weight: 2200
}
};
// Push operation into the transction
tx.pushOperation(operation);
// Build transaction with signature provided.
await signer1.signTransaction(tx);
console.log(tx.toApi());
{
"ref_block_num": 1960,
"ref_block_prefix": 3915120327,
"expiration": "2023-11-09T21:51:27",
"operations": [
{
"type": "vote_operation",
"value": {
"voter": "voter",
"author": "author",
"permlink": "test-permlink",
"weight": 2200
}
}
],
"signatures": [
"1fe8647a82f131671997ce26250bf5a1cb7a18609cbc69b3b2fd7fcaefc848c7fc308abfb0992c1ce9a805715f102416d85c4313a8a00527fa1500ac93898b418a"
]
}
TBA
You can also sign the transaction without converting it to the API form (which will return the signatures):
import { createHiveChain } from '@hiveio/wax';
// Initialize hive chain interface
const chain = await createHiveChain();
const { signer1 } = globalThis.snippetsBeekeeperData;
// Initialize a transaction object
const tx = await chain.createTransaction();
// Declare example operation
const operation = {
vote_operation: {
voter: "voter",
author: "author",
permlink: "test-permlink",
weight: 2200
}
};
// Push operation into the transction
tx.pushOperation(operation);
// Sign transaction.
await signer1.signTransaction(tx);
console.log(tx.transaction.signatures[0]);
1fe8647a82f131671997ce26250bf5a1cb7a18609cbc69b3b2fd7fcaefc848c7fc308abfb0992c1ce9a805715f102416d85c4313a8a00527fa1500ac93898b418a
TBA
Beekeeper Information
If you want to sign the transaction after creating it, using our ITransaction
interface, you should use one of the available signers. Remember to import keys into Beekeeper. It ensures that you can use them securely for transactions and other operations without exposing the raw keys.
Imported key and the one you want to use for signing must be the same!
#
Conversions
At the end you can also just convert your transaction into the Hive API-form JSON:
import { createHiveChain } from '@hiveio/wax';
// Initialize hive chain interface
const chain = await createHiveChain();
// Initialize a transaction object
const tx = await chain.createTransaction();
// Declare example operation
const operation = {
vote_operation: {
voter: "voter",
author: "test-author",
permlink: "test-permlink",
weight: 2200
}
};
// Push operation into the transction
tx.pushOperation(operation);
// Convert transaction into the Hive API-form JSON.
const apiTx = tx.toApi();
console.log(apiTx);
{
"ref_block_num": 1960,
"ref_block_prefix": 3915120327,
"expiration": "2023-11-09T21:51:27",
"operations": [
{
"type": "vote_operation",
"value": {
"voter": "voter",
"author": "test-author",
"permlink": "test-permlink",
"weight": 2200
}
}
]
}
TBA
Or you can just convert transction to legacy API form:
import { createHiveChain } from '@hiveio/wax';
// Initialize hive chain interface
const chain = await createHiveChain();
// Initialize a transaction object
const tx = await chain.createTransaction();
// Declare example operation
const operation = {
vote_operation: {
voter: "voter",
author: "test-author",
permlink: "test-permlink",
weight: 2200
}
};
// Push operation into the transction
tx.pushOperation(operation);
// Convert transaction into the Hive API-legacy form JSON string
const legacyApiTx = tx.toLegacyApi();
console.log(legacyApiTx);
{
"ref_block_num": 1960,
"ref_block_prefix": 3915120327,
"expiration": "2023-11-09T21:51:27",
"operations": [
[
"vote",
{
"voter": "voter",
"author": "test-author",
"permlink": "test-permlink",
"weight": 2200
}
]
],
"extensions": [],
"signatures": []
}
TBA