Ethereum: Smart Contract Execution transaction fee
As a developer who builds intelligent contracts on the Ethereum blockchain, you are probably familiar with the importance of managing transaction fees. In this article we will deal with the concept of transaction fees and your work in Ethereum, whereby we focus specifically on the execution of Smart Contract.
Transaction fees for Ethereum
At Ethereum, transactions are subject to a fee to facilitate value transmission in the entire network. The sender pays a transaction fee to the network for processing its transaction. This fee is used to drive nodes to validate every block and to ensure the integrity of the blockchain.
The transaction fee is calculated based on several factors:
- Block height : Blocks of the chain are added, the fees are also.
- Transaction complexity : more complex transactions, such as B. those with multiple inputs or outputs, higher fees are created.
- Network overload : In an overloaded network, fees can be higher due to an increased transaction load.
Smart Contract Execution Transaction Fee **
In smart contracts you can use the Ethereum Virtual Machine (EVM) to carry out transactions and manage funds. When it comes to deducting certain amounts from token received in a contract, the EVM implemented a function called “Fonds Transfer”. In this way, the contract can transfer funds between accounts on the blockchain.
The transaction fee structure
In order to understand how transaction fees work in smart contracts from Ethereum, we set off the structure:
- Recipient account : The sender of token (the recipient) is responsible for the administration of his own balance.
- Contract execution : If a contract is carried out, he sends a “call” or “sending” of message to the Ethereum network.
- Transactional creation : A new transaction is created and sent to the network.
- Fund transmission : The EVM checks whether there is sufficient means in the recipient’s account to cover the transaction fee.
How fees work
Here is an example of a simple intelligent contract that deducts 10 US dollars from the token obtained and forwards the remaining remaining amount to a specific target address:
`Solidity
Pragma solidity ^0.8.0;
Contract transfer controller {
Mapping (address => uint256) public credit;
Address the public recipient’s address;
Constructor () public {
Balances [Msg.sender] = 100000000; // First record for the sender
}
Functional recipient (Uint256 _AMOUNT) Public {
require (balances [msg.sender]> = _amount, “inadequate means”);
// Peel 10 US dollars from token and send it to the recipient
Balances [Msg.sender] -= 10000;
Balances [Recicentaddress] += 200000; // forward the remaining balance
Emit transmission (msg.sender, Receciquetaddress, 20);
}
Function Transfertorecipient (address _Recipient) Public {
require (balances [msg.sender]> = 1, “inadequate means”);
Balances [msg.sender] -= 10;
Balances [_Recipient] += 10;
Emit transmission (msg.sender, _recipient, 5);
}
}
`
Transaction fee calculation
In this example, the transaction fee based on the block height and the complexity of the transaction (number of inputs or outputs) is calculated. For the sake of simplicity, we will accept a moderate level of complexity.
With the assumption of an average block height of 1000 blocks per second, the calculation would be:
- Block height: 1000
- Transaction complexity: 5 inputs and 3 outputs (a total of 8 inputs)
- Fee assignment:
* 40% for block height fees (~ $ 400 per block)
* 30% for transaction complexity fees (~ 300 USD per block)
* 20% for fees for network jams (~ 200 USD per block)
Based on these assumptions, the transaction fee would be around $ 800 (40% out of USD 2000).
Diploma
In this article we examined the concept of transaction fees in smart contracts from Ethereum.
Leave a Reply