To create a transaction using a TransactionBuilder, you need to:
Add an input: This involves providing the transaction hash (txHash) of a previous transaction that contains the unspent transaction output (UTXO) you want to use as an input, along with the index of the UTXO in that transaction. Additionally, you need to provide the private key associated with the UTXO's address.
Add an output: This involves specifying the receiver's address (where you want to send the funds), the amount of Kalapas (the cryptocurrency) to send, and the asset ID (the identifier of the asset being transferred).
Once you have added the input and output to the transaction, you can proceed to sign it. The signing process involves using the private key associated with the input UTXO to create a digital signature for the transaction. The signature ensures the integrity and authenticity of the transaction.
After the transaction is signed, it needs to be transformed into hexadecimal format (hex) so that it can be published on the network. This encoding ensures that the transaction can be transmitted and understood by the blockchain network.
Here an example:
import {TransactionBuilder,ExtendedKey} from'@zen/zenjs'import {post} from'axios'constmnemonic='one one one one one one one one one one one one one one one one one one one one one one one one';constprivateKey=ExtendedKey.fromMnemonic(mnemonic).derivePath("m/44'/258'/0'/0/0").getPrivateKey();consttb=newTransactionBuilder('test');tb.addInput('0000000000000000000000000000000000000000000000000000000000000000',0, privateKey);tb.addOutput('tp1qfyplhxql09lvvg53dxg7t77tkkxhsp3l6q8xjjpj85hvqlw0ttqswjdapx',100,'00');consttx=tb.sign();console.log(tx.hash(),tx.toJson());consthex=tx.toHex();// Transaction is ready to be published post('http://127.0.0.1/:31567/blockchain/publishtransaction',hex,{ headers: { 'Content-Type':'application/json' }});