Implementing Transactions
This guide provides a comprehensive overview of implementing transactions on the Kaia network, covering various transaction types, encoding, signing, and network interaction.
Kaia Transaction Components
Kaia transactions generally include the following components:
Components | Description |
---|---|
from | The sender's address. Required for most Kaia transaction types due to the decoupling of key pairs and addresses. |
to | The account address that will receive the transferred value. |
value | The amount of KAIA in kei to be transferred. |
input | Data attached to the transaction, used for transaction execution. |
v , r , s | The cryptographic signature generated by the sender to let the receiver obtain the sender's address. |
nonce | A value used to uniquely identify a sender’s transaction. If two transactions with the same nonce are generated by a sender, only one is executed. |
gas | The maximum amount of transaction fee the transaction is allowed to use. |
gasPrice | A multiplier to get how much the sender will pay in tokens. The amount of tokens the sender will pay is calculated via gas * gasPrice . For example, the sender will pay 10 KAIA for a transaction fee if gas is 10 and gasPrice is 10^18. Unit of KAIA is described here. |
Signature Validation
Because Kaia decouples key pairs from addresses, signature validation differs from typical blockchains. The from
field is crucial, as it identifies the sender. The AccountKey associated with the from
address is used to validate the signature.
Fee Delegation and SenderTxHash
Kaia's fee delegation feature allows a third party to pay transaction fees. This requires two signatures – one from the sender and one from the fee payer. The SenderTxHash
is crucial for tracking fee-delegated transactions. It's a hash of the transaction without the fee payer's information, allowing the sender to track the transaction before the fee payer signs it. The sender can use the SenderTxHash
to retrieve the complete transaction via the kaia_getTransactionBySenderTxHash RPC method.
Transaction Types
While typical Blockchain platforms provide a single transaction type, Kaia provides multiple transaction types that empower transactions with new capabilities and optimizations for memory footprint and performance. The following table provides an overview of the transaction types available on Kaia:
Implementation Details
- RLP Encoding: Transactions are serialized using Recursive Length Prefix (RLP) encoding before submission.
- Signatures: Transactions are signed using [Specify signature algorithm, e.g., ECDSA] to ensure authenticity.
- Examples and RPC Outputs: This section will provide practical examples and expected RPC outputs for each transaction type. (Note:
TxTypeValueTransfer
sends KAIA without any additional data, whileTxTypeValueTransferMemo
allows for including a short memo field along with the transfer.)
By understanding these components and implementation details, developers can effectively build applications on the Kaia network.