Basic
TxTypeLegacyTransaction
TxTypeLegacyTransaction represents a type of transactions existed previously in Klaytn. Since this transaction type exists to support compatibility, it only works with EOAs associated with AccountKeyLegacy. EOAs associated with other account key types should use other transaction types such as TxTypeValueTransfer, TxTypeSmartContractExecution, and so on. This type of transaction can create an account, transfer tokens, deploy a smart contract, execute a smart contract, or perform a mix of aforementioned. This transaction type will initiate the following changes.
The sender's balance decreases by the amount of the transaction fee.
The sender's nonce increases by one.
If
todoes not exist on Klaytn, an EOA associated with AccountKeyLegacy is created.valueKLAY is transferred from the sender to the recipient.If
tois nil, it is regarded as a smart contract deployment transaction. The smart contract code must be passed asinput.If
tois a smart contract, the smart contract function specified ininputis executed.
Attributes
value
*big.Int (Go)
The amount of KLAY in peb to be transferred.
to
*common.Address (Go)
The account address that will receive the transferred value.
input
[]byte (Go)
Data attached to the transaction, used for transaction execution.
v, r, s
*big.Int (Go)
The cryptographic signature generated by the sender to let the receiver obtain the sender's address.
nonce
uint64 (Go)
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
uint64 (Go)
The maximum amount of transaction fee the transaction is allowed to use.
gasPrice
*big.Int (Go)
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 KLAY for a transaction fee if gas is 10 and gasPrice is 10^18. See Unit of KLAY.
RLP Encoding for Signature
To make a signature of this transaction type, RLP serialization should be done like the following:
RLP Encoding for SenderTxHash
To make a SenderTxHash, RLP serialization should be done like the following:
RLP Encoding for Transaction Hash
To make a transaction hash, RLP serialization should be done like the following:
RLP Encoding (Example)
The following shows the result of RLP serialization and the transaction object:
RPC Output (Example)
The following shows a transaction object returned via JSON RPC.
TxTypeValueTransfer
TxTypeValueTransfer is used when a user wants to send KLAY. As Klaytn provides multiple transaction types to make each transaction type serve a single purpose, TxTypeValueTransfer is limited to send KLAY to an externally owned account. Therefore, TxTypeValueTransfer is accepted only if to is an externally owned account. To transfer KLAY to a smart contract account, use TxTypeSmartContractExecution instead. The following changes will be made by this transaction type.
The sender's balance decreases by the amount of the transaction fee.
The sender's nonce increases by one.
valueKLAY is transferred from the sender to the recipient.
Attributes
type
uint8 (Go)
The type of TxTypeValueTransfer. This must be 0x08.
nonce
uint64 (Go)
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.
gasPrice
*big.Int (Go)
A unit price of gas in peb the sender will pay for a transaction fee. The amount of transaction fee is calculated as gas * gasPrice. For example, if the transaction consumes 10 units of gas and gasPrice is 10^18, the transaction fee will be 10 KLAY. See Unit of KLAY.
gas
uint64 (Go)
The maximum amount of gas the transaction is allowed to use.
to
common.Address (Go)
The account address that will receive the transferred value.
value
*big.Int (Go)
The amount of KLAY in peb to be transferred.
from
common.Address (Go)
The address of the sender. For more details, see Signature Validation of Transactions.
txSignatures
[]{*big.Int, *big.Int, *big.Int} (Go)
The sender's signatures. For more details, see Signature Validation of Transactions.
RLP Encoding for Signature
To make a transaction signature, RLP serialization should be done like the following:
RLP Encoding for SenderTxHash
To make a SenderTxHash, RLP serialization should be done like the following:
RLP Encoding for Transaction Hash
To make a transaction hash, RLP serialization should be done like the following:
RLP Encoding (Example)
The following shows the result of RLP serialization with the given parameters and the information of the transaction object:
RPC Output (Example)
The following shows a transaction object returned via JSON RPC.
TxTypeValueTransferMemo
TxTypeValueTransferMemo is used when a user wants to send KLAY with a specific message. TxTypeValueTransferMemo is accepted only if to is an externally owned account. To transfer KLAY to a smart contract account, use TxTypeSmartContractExecution instead. The following changes will be made by this transaction type.
The sender's balance decreases by the amount of the transaction fee.
The sender's nonce increases by one.
valueKLAY is transferred from the sender to the recipient.
Attributes
type
uint8 (Go)
The type of TxTypeValueTransferMemo. This must be 0x10.
nonce
uint64 (Go)
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.
gasPrice
*big.Int (Go)
A unit price of gas in peb the sender will pay for a transaction fee. The amount of transaction fee is calculated as gas * gasPrice. For example, if the transaction consumes 10 units of gas and gasPrice is 10^18, the transaction fee will be 10 KLAY. See Unit of KLAY.
gas
uint64 (Go)
The maximum amount of gas the transaction is allowed to use.
to
common.Address (Go)
The account address that will receive the transferred value.
value
*big.Int (Go)
The amount of KLAY in peb to be transferred.
from
common.Address (Go)
The address of the sender. For more details, see Signature Validation of Transactions.
input
[]byte (Go)
Data attached to the transaction. The message should be passed to this attribute.
txSignatures
[]{*big.Int, *big.Int, *big.Int} (Go)
The sender's signatures. For more details, see Signature Validation of Transactions.
RLP Encoding for Signature
To make a transaction signature, RLP serialization should be done like the following:
RLP Encoding for SenderTxHash
To make a SenderTxHash, RLP serialization should be done like the following:
RLP Encoding for Transaction Hash
To make a transaction hash, RLP serialization should be done like the following:
RLP Encoding (Example)
The following shows the result of RLP serialization and the transaction object:
RPC Output (Example)
The following shows a transaction object returned via JSON RPC.
TxTypeSmartContractDeploy
TxTypeSmartContractDeploy deploys a smart contract to the given address. The following changes will be made by this transaction type.
The sender's balance decreases by the amount of the transaction fee.
The sender's nonce increases by one.
A smart contract is deployed with the code in
input. The deployed address will be returned viacontractAddressin the receipt.valueKLAY is transferred from the sender to the recipient.
Attributes
type
uint8 (Go)
The type of TxTypeSmartContractDeploy. This must be 0x28.
nonce
uint64 (Go)
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.
gasPrice
*big.Int (Go)
A unit price of gas in peb the sender will pay for a transaction fee. The amount of transaction fee is calculated as gas * gasPrice. For example, if the transaction consumes 10 units of gas and gasPrice is 10^18, the transaction fee will be 10 KLAY. See Unit of KLAY.
gas
uint64 (Go)
The maximum amount of gas the transaction is allowed to use.
to
*common.Address (Go)
The account address that will receive the transferred value. Currently, this value must be nil. Specifying the address will be supported in the future.
value
*big.Int (Go)
The amount of KLAY in peb to be transferred.
from
common.Address (Go)
The address of the sender. For more details, see Signature Validation of Transactions.
input
[]byte (Go)
Data attached to the transaction, used for transaction execution.
humanReadable
bool (Go)
This must be false since human-readable address is not supported yet. If true, the transaction will be rejected.
codeFormat
uint8 (Go)
The code format of smart contract code. The supported value for now is EVM(0x00) only.
txSignatures
[]{*big.Int, *big.Int, *big.Int} (Go)
The sender's signatures. For more details, see Signature Validation of Transactions.
RLP Encoding for Signature
To make a signature of this transaction type, RLP serialization should be done like the following:
RLP Encoding for SenderTxHash
To make a SenderTxHash, RLP serialization should be done like the following:
RLP Encoding for Transaction Hash
To make a transaction signature of the fee payer, RLP serialization should be done like the following:
RLP Encoding (Example)
The following shows the result of RLP serialization and the transaction object:
RPC Output (Example)
The following shows a transaction object returned via JSON RPC.
TxTypeSmartContractExecution
TxTypeSmartContractExecution executes a smart contract with the given data in input. TxTypeSmartContractExecution is accepted only if to is a smart contract account. To transfer KLAY to an externally owned account, use TxTypeValueTransfer instead. The following changes will be made by this transaction type.
If
tois a smart contract account, the code is executed based oninput. Otherwise, this transaction will be rejected.The sender's balance decreases by the amount of the transaction fee.
The sender's nonce increases by one.
If
valuewas provided,valueKLAY is transferred from the sender to thetosmart contract. The contract should have a payable fallback function to receive KLAY.
Attributes
type
uint8 (Go)
The type of TxTypeSmartContractExecution. This must be 0x30.
nonce
uint64 (Go)
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.
gasPrice
*big.Int (Go)
A unit price of gas in peb the sender will pay for a transaction fee. The amount of transaction fee is calculated as gas * gasPrice. For example, if the transaction consumes 10 units of gas and gasPrice is 10^18, the transaction fee will be 10 KLAY. See Unit of KLAY.
gas
uint64 (Go)
The maximum amount of gas the transaction is allowed to use.
to
common.Address (Go)
The address of the smart contract account to be executed.
value
*big.Int (Go)
The amount of KLAY in peb to be transferred.
from
common.Address (Go)
The address of the sender. For more details, see Signature Validation of Transactions.
input
[]byte (Go)
Data attached to the transaction, used for transaction execution.
txSignatures
[]{*big.Int, *big.Int, *big.Int} (Go)
The sender's signatures. For more details, see Signature Validation of Transactions.
RLP Encoding for Signature
To make a signature of this transaction type, RLP serialization should be done like the following:
RLP Encoding for SenderTxHash
To make a SenderTxHash, RLP serialization should be done like the following:
RLP Encoding for Transaction Hash
To make a transaction hash, RLP serialization should be done like the following:
RLP Encoding (Example)
The following shows the result of RLP serialization and the transaction object:
RPC Output (Example)
The following shows a transaction object returned via JSON RPC.
TxTypeAccountUpdate
TxTypeAccountUpdate updates the key of the given account. The following changes will apply by this transaction type.
The sender's balance decreases by the amount of the transaction fee.
The sender's nonce increases by one.
The account's key is updated with
key.Once this type of transaction is executed, transactions sent from the account afterward will be validated with the new
key.
Attributes
type
uint8 (Go)
The type of TxTypeAccountUpdate. This must be 0x20.
nonce
uint64 (Go)
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.
gasPrice
*big.Int (Go)
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 KLAY for a transaction fee if gas is 10 and gasPrice is 10^18. See Unit of KLAY.
gas
uint64 (Go)
The maximum amount of transaction fee the transaction is allowed to use.
from
common.Address (Go)
The address of the sender. For more details, see Signature Validation of Transactions.
txSignatures
[]{*big.Int, *big.Int, *big.Int} (Go)
The sender's signatures. For more details, see Signature Validation of Transactions.
RLP Encoding for Signature
To make a signature of this transaction type, RLP serialization should be done like the following:
RLP Encoding for SenderTxHash
To make a SenderTxHash, RLP serialization should be done like the following:
RLP Encoding for Transaction Hash
To make a transaction hash, RLP serialization should be done like the following:
RLP Encoding (Example)
The following shows the result of RLP serialization and the transaction object:
RPC Output (Example)
The following shows a transaction object returned via JSON RPC.
TxTypeCancel
TxTypeCancel cancels the execution of the transaction with the same nonce in the transaction pool. This transaction type is useful when a submitted transaction seems unprocessed for a certain amount of time. There are several cases that a transaction seems unprocessed: 1. The transaction was lost somewhere and did not reach any of the consensus nodes. 2. The transaction has not been processed yet in any of the consensus nodes. 3. The transaction was processed, but the block containing the transaction has not been received.
From the client side, it is very hard to figure out the exact reason because to figure out the reason, it is required to look inside all the consensus nodes. However, connecting to any of the consensus nodes from the public is prohibited. Under this situation, in typical blockchain platforms, the user often submits another transaction with a higher gas price to replace the old transaction. However, because the gas price is fixed in Klaytn, replacing the old transaction with a higher gas price is not applicable.
If the transaction remains unprocessed, the other transactions with higher nonce cannot be processed because the nonce determines the execution order of transactions.
To solve this problem, Klaytn provides a transaction type TxTypeCancel. If a user encountered such a situation, a transaction of TxTypeCancel can be submitted.
Each of the above situations is handled as follows: 1. If the old transaction was lost, this TxTypeCancel transaction is executed and included in a block. 2. If the old transaction has not been processed yet, this TxTypeCancel replaces the old transaction. Then, it is executed and included in a block. 3. if the old transaction was already executed, the nonce has been increased, therefore this TxTypeCancel transaction is discarded due to the lower nonce.
Note that the TxTypeCancel transaction is the only transaction that is capable of replacing a transaction with the same nonce. Other transaction types cannot replace the transactions with the same nonce.
The following changes can occur by this transaction type. 1. The sender's balance decreases by the amount of the transaction fee. 2. The sender's nonce increases by one.
Attributes
type
uint8 (Go)
The type of TxTypeCancel. This must be 0x38.
nonce
uint64 (Go)
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. For the TxTypeCancel transaction, this value must match the nonce that the target transaction to be canceled was using.
gasPrice
*big.Int (Go)
A unit price of gas in peb the sender will pay for a transaction fee. The amount of transaction fee is calculated as gas * gasPrice. For example, if the transaction consumes 10 units of gas and gasPrice is 10^18, the transaction fee will be 10 KLAY. See Unit of KLAY.
gas
uint64 (Go)
The maximum amount of transaction fee the transaction is allowed to use.
from
common.Address (Go)
The address of the sender. For more details, see Signature Validation of Transactions.
txSignatures
[]{*big.Int, *big.Int, *big.Int} (Go)
The sender's signatures. For more details, see Signature Validation of Transactions.
Outcome:
If there is a transaction with the same nonce, it is replaced with this cancel transaction.
If no same nonce, this transaction is just inserted as a normal transaction.
The cancel transaction is not replaced with other transaction types.
RLP Encoding for Signature
To make a transaction signature, RLP serialization should be done like the following:
RLP Encoding for SenderTxHash
To make a SenderTxHash, RLP serialization should be done like the following:
RLP Encoding for Transaction Hash
To make a transaction hash, RLP serialization should be done like the following:
RLP Encoding (Example)
The following shows the result of RLP serialization and the transaction object:
RPC Output (Example)
The following shows a transaction object returned via JSON RPC.
TxTypeChainDataAnchoring
TxTypeChainDataAnchoringTransaction is a transaction that anchors service chain data to the Klaytn mainchain. Service chains periodically send this type of transaction to the Klaytn mainchain to ensure its security and credibility of data. For more details about the data anchoring, see Anchoring. Be mindful that it is not allowed to send this transaction via RPC. Currently, this transaction is executed through private p2p channels for security reasons. This transaction does not change the state of the Klaytn blockchain except the sender's nonce being increased by one.
Attributes
type
uint8 (Go)
The type of TxTypeChainDataAnchoringTransaction. This must be 0x48.
nonce
uint64 (Go)
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.
gasPrice
*big.Int (Go)
A unit price of gas in peb the sender will pay for a transaction fee. The amount of transaction fee is calculated as gas * gasPrice. For example, if the transaction consumes 10 units of gas and gasPrice is 10^18, the transaction fee will be 10 KLAY. See Unit of KLAY.
gas
uint64 (Go)
The maximum amount of transaction fee the transaction is allowed to use.
from
common.Address (Go)
The address of the sender. For more details, see Signature Validation of Transactions.
input
[]byte (Go)
Data of the service chain.
txSignatures
[]{*big.Int, *big.Int, *big.Int} (Go)
The sender's signatures. For more details, see Signature Validation of Transactions.
RLP Encoding for Signature
To make a signature of this transaction type, RLP serialization should be done like the following:
RLP Encoding for SenderTxHash
To make a SenderTxHash, RLP serialization should be done like the following:
RLP Encoding for Transaction Hash
To make a transaction hash, RLP serialization should be done like the following:
RLP Encoding (Example)
The following shows the result of RLP serialization and the transaction object:
RPC Output (Example)
The following shows a transaction object returned via JSON RPC.
Last updated