Ethereum: Error for Reducing Low Level Error
The Ethereum blockchain is a programmable blockchain where smart contracts can be deployed and executed. However, errors such as execution errors were reactivated during the execution of low -level calls to external functions.
In this article,
What are the causes of an execution error?
Contract Intelligent This can happen for several reasons:
- Signature of non -valid function
:
- Lacking compulsory arguments *: one or more arguments required are missing on the call of function, which makes it fail.
.
Example of a Gas Oracle Appeal
In Ethereum, the “Gasoracle” api is used to recover the cost of the estimated gas for a transaction. This api can be called from another routine or intelligent contract using the following Syntax:
`Solidity
Estimatedgas Function () Returns Public (Uint256) {
// API Gasoracle Call and Analysis Result
uint256 estimatedgas = 0; // Initialize the variable
Gasoracle Gasoracle = New Gasoracle (Address);
Gasoracle.istimatricas (); // Gasoracle Call API
Estimatedgas = gasoracle. // Analysis Result
Estimated Yield;
}
'
The cost of the estimated gas and returns it.
The Example of Execution has remained an error
Let's see an example where we have a simple intelligent contract that tries to call a function:
Solidity
Example of contract {
Foo () Public Function {
// Call Bar ()
Callbar ();
}
PURE PUBLIC FUNTION ()
// simulate and calculation
Result Uint256 = 0;
for (uint256 i = 0; i <100000; i ++) {
Result + = i;
}
Return Result;
}
}
'
Assuming that we have an appeal APIGasoraclein another routine, the function of () 'Tries to call the function
bar ()’:
`Solidity
Pragma solidity ^ 0.8,0;
Example of contract {
// API Oracle to Gas
Uint256 Public Gascost;
Estimatedgas Function () Returns Public (Uint256) {
Gascost = 0; // Initialize the variable
Gasoracle Gasoracle = New Gasoracle (Address);
Gasoracle.istimatricas (); // Gasoracle Call API
Gasoracle.gettestimatedgas (); // Analysis Result
Gascost Back;
}
}
'
When The Ethereum blockchain does not allow to call a function which is not declared "pure" or which has correct signatures.
Resolution
Contracts. In this case, we can simply modify the functionbar ()to be pure:
Solidity
Example of contract {
Foo () Public Function {
// Call Bar ()
Callbar ();
}
Function Bar () Pure Return Public (Uint256) {
// simulate and calculation
Result Uint256 = 0;
for (uint256 i = 0; i <100000; i ++) {
Result + = i;
}
Return Result;
}
}
'
With this change, we can safely` foo () ‘without meeting an error of execution of execution. API calls are executed and do not exceed the authorized gas limit.