Ethereum: Solve gas restriction in chain calls
As Ethereum developer, the concept of gas restrictions in an intelligent contract is probably knowing. When a characteristic is called the execution of the Ethereum virtual machine (EVM), EVM has limited resources for each characteristic call. Gas restrictions are played here.
When calling another contract or function of another contract, it is customary to see the calls of the chain introduced, where several characteristics are called sequentially. However, when it comes to this “Gaslimit” call parameter, things are becoming interesting.
In this article, we will enter the concept of gas edge and how they are used in chain bells, with an example using the strength of the Ethereum block chain.
What is a gas limit?
Gas restriction is a limit for the amount of gas (currency units in the Ethereum Network), which can be spent with the function during execution. Gas restriction is determined when the contract or function is placed and executed by EVM.
When a function call is made, the EVM verifies whether gas resources are available before continuing. If the account does not have enough gas, the transaction is rejected and the sender’s wallet will freeze until more gas is available.
Chain calls: how gas restrictions work

Now let’s consider an example of an a call chain to another contract or characteristic using Chainall. In this case, we will use the stability language as an example.
`SOLIDITY
Pragma solidity ^0.8.0;
An example of a contract {
// Function A: A simple feature that performs some action
Function A () Public {
(Bool Success,) = Address (This) .Call {Gas: 10000} (both.encodewithselector (This.B.Selector));
Console.log ("successful action");
}
// Function B: Another feature that requires that gas pass
Function B () Public {
Request (eters.utils.gaslimit ()> = 1000001, "insufficient gas remains to adhere");
(Bool Success,) = Address (This) .Call {Gas: 1500000} (both.
Console.log ("B realized");
}
}
In the previous example, we have two characteristics:aand 'b'. The "A call another contract or function using" Chainall "with a gas restriction of 1 million. EVM verifies that there is enough gas before continuing.
However, by calling the "B", EVM verifies the gas available again and requires at least 1.5 million gas (1000001 + 1500000), which must endure in a A function, if not sufficient gas, the transaction will be refused.
Gas limit in chain calls
In this example, we see that the Gaslimit parameter is used to implement special gas requirements for each call. In chain calls, EVS verifies that there are enough resources available before continuing each function.
To solve Gaslimit, we must consider the total gas costs of all the chained so -called. The formula for calculating the required gas limit is:
Gaslimit = Max ((Totalgascost / Gaspercall) + 1, min (Gaslimit, Ceil (Log2 (Totalgascost))
Here is a simplified example:
`SOLIDITY
Pragma solidity ^0.8.0;
An example of a contract {
// Total gas costs: 1000001
Uint Totalgasost;
// gas in a call to a
Uint Gaspercall = 1500000;
// constant evm
Uint Maxgaslimit = 20000000; // Arbitrary value
Function Getratedgaslimit () public view return (uint) {
TOTALGASCOST = 1000001 + GASPERCALL * 10; // Add a small amount of gas for safety
Return maxgaslimit - tceil (log2 (totalgascost));
}
}
`
In this example, we calculate the required gas restriction repeating all the chained calls and counting their total gas costs.
Yazar hakkında