The transaction fee for the current Klaytn virtual machine (KLVM) is computed as follows:
Transaction fee := (total gas used) x (unit price)
total gas used is computed by KLVM based on the gas cost of the opcode and the intrinsic gas cost.
unit price is 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
Gas is a measuring unit representing how much calculation is needed to process the user's transaction.
Unit price is 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 25 Gpeb (i.e., 25 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 price is 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.
Nothing paid for operations of the set Wzero
Amount of gas to pay for operations of the set Wbase
Amount of gas to pay for operations of the set Wverylow
Amount of gas to pay for operations of the set Wlow
Amount of gas to pay for operations of the set Wmid
Amount of gas to pay for operations of the set Whigh
Payment for BLOCKHASH operation
Amount of gas to pay for operations of the set Wextcode
Amount of gas to pay for a BALANCE operation
Paid for a SLOAD operation
Paid for a JUMPDEST operation
Paid for an SSTORE operation when the storage value is set to non-zero from zero
Paid for an SSTORE operation when the storage value’s zeroness remains unchanged or is set to zero
Refund given (added into refund counter) when the storage value is set to zero from non-zero
Refund given (added into refund counter) for self-destructing an account
Amount of gas to pay for a SELFDESTRUCT operation
Paid for a CREATE operation
Paid per byte for a CREATE operation to succeed in placing code into state
Paid for a CALL operation
Paid for a non-zero value transfer as part of the CALL operation
A stipend for the called contract subtracted from Gcallvalue for a non-zero value transfer
Paid for a CALL or SELFDESTRUCT operation which creates an account
Partial payment for an EXP operation
Partial payment when multiplied by dlog256(exponent)e for the EXP operation
Paid for every additional word when expanding memory
Paid by all contract-creating transactions
Paid for every transaction
Partial payment for a LOG operation
Paid for each byte in a LOG operation’s data
Paid for each topic of a LOG operation
Paid for each SHA3 operation
Paid for each word (rounded up) for input data to a SHA3 operation
Partial payment for *COPY operations, multiplied by words copied, rounded up
Payment for BLOCKHASH operation
Paid for getting keccak256 hash of a contract's code
Paid for opcode CREATE2 which bahaves identically with CREATE but use different arguemnts
Precompiled contracts are special kind of contracts which usually perform complex cryptographic computations and are initiated by other contracts.
Perform ECRecover operaton
Perform sha256 hash operation
Perform Ripemd160 operation
Perform Bn256 elliptic curve operation
Write logs to node's log file - Klaytn only
Get feePayer's address - Klaytn only
5000 per signature
Validate the sender's address and signature - Klaytn only
Total gas of those items which has XXXBaseGas and XXXPerWordGas (e.g. Sha256BaseGas, Sha256PerWordGas) are calcluated as
TotalGas = XXXBaseGas + (number of words * XXXPerWordGas)
ValidateSenderGas have to be paid per signature basis.
TotalGas = number of signatures * ValidateSenderGas
Gas required for a key-pair creation
Gas required for a key validation
Gas required for an account update
Gas required for a fee delegation
Gas required for a fee delegation with ratio
Gas required to cancel a transaction which has a same nonce
Gas required to transfer KLAY
Base gas for contract execution
Gas required per transaction's single byte
Gas for payload data is calculated as below
GasPayload = number_of_bytes * TxDataGas
TxGas + PayloadGas + KeyValidationGas
TxGasValueTransfer + KeyValidationGas
TxGasValueTransfer + PayloadGas + KeyValidationGas
TxGasAccountUpdate + KeyCreationGas + KeyValidationGas
TxGasContractCreation + PayloadGas + KeyValidationGas
TxGasContractExecution + PayloadGas + KeyValidationGas
TxGasCancel + KeyValidationGas
KeyValidationGas is defined as below based on key type,
(keys-1) * GasValidationPerKey (15000)
Based on keys in the role used in the validation
KeyCreationGas is defined as below based on key type,
(keys) * GasCreationPerKey
Gas fee calculated based on keys in each role. e.g., GasRoleTransaction = (keys) GasCreationPerKey GasRoleAccountUpdate = (keys) GasCreationPerKey GasRoleFeePayer = (keys) * GasCreationPerKey