Transaction Fees (Previous docs)
The transaction fee for the current Klaytn virtual machine (KLVM) is computed as follows:
Transaction fee := (total gas used) x (unit price)
total gas usedis computed by KLVM based on the gas cost of the opcode and the intrinsic gas cost.
unit priceis the price of gas defined in Klaytn.
This calculated transaction fee is subtracted from the sender's or enterprise account's balance, depending on the transaction.
Every action that changes the state of the blockchain requires gas. When a node processes user's transaction such as sending KLAY, using ERC-20 tokens, or executing a contract, the user has to pay for the computation and storage usage. The amount of payment is decided by the amount of
Gasis a measuring unit representing how much calculation is needed to process the user's transaction.
Unit priceis the price for a single gas. The unit price (also called
gas price) is set in the system by the governance. It is currently set to 250 ston (i.e., 250 x 10^9 peb) per gas and cannot be changed by user. The current value of the unit price can be obtained by calling the
In Ethereum, users set the gas price for each transaction, and miners choose which transactions to be included in their block to maximize their reward. It is something like bidding for limited resources. This approach has been working because it is market-based. However, the transaction cost fluctuates and often becomes too high to guarantee the execution.
To solve the problem, Klaytn is using a fixed unit price and the price can be adjusted by the governance council. This policy ensures that every transaction will be handled equally and be guaranteed to be executed. Therefore, users do not need to struggle to determine the right unit price.
Klaytn only accepts transactions with gas prices, which can be set by the user, that are equal to the unit price of Klaytn; it rejects transactions with gas prices that are different from the unit price in Klaytn.
The error message
invalid unit priceis returned when the gas price of a transaction is not equal to the unit price of Klaytn.
Klaytn currently does not provide a way to replace a transaction using the unit price but may support different methods for the transaction replacement in the future. Note that in Ethereum, a transaction with a given nonce can be replaced by a new one with a higher gas price.
Basically, Klaytn is keeping compatibility with Ethereum. So Klaytn's gas table is pretty similar with that of Ethereum. But because of the existence of unique features of Klaytn, there are several new constants for those features.
Precompiled contracts are special kind of contracts which usually perform complex cryptographic computations and are initiated by other contracts.
Total gas of those items which has XXXBaseGas and XXXPerWordGas (e.g. Sha256BaseGas, Sha256PerWordGas) are calculated as
TotalGas = XXXBaseGas + (number of words * XXXPerWordGas)
ValidateSenderGas have to be paid per signature basis.
TotalGas = number of signatures * ValidateSenderGas
Gas for payload data is calculated as below
GasPayload = number_of_bytes * TxDataGas
KeyValidationGas is defined as below based on key type,
KeyCreationGas is defined as below based on key type,