Library
Solidityपरिभाषा
Library एक special type का contract है जो reusable code contain करता है। Libraries state variables नहीं रख सकते और ether receive नहीं कर सकते। Library functions को "using for" directive के साथ किसी भी type पर attach किया जा सकता है। Libraries gas optimize करने के लिए useful हैं।
English version
Library is a special type of contract that contains reusable code. Libraries cannot have state variables and cannot receive ether. Library functions can be attached to any type using the "using for" directive. Libraries are useful for gas optimization.
Code Example
// Bibliothèque SafeMath
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "Overflow");
return c;
}
}
// Utilisation
contract MyContract {
using SafeMath for uint256;
function calculate(uint256 a, uint256 b) public pure returns (uint256) {
return a.add(b); // Appel de bibliothèque
}
}संबंधित शब्द
संबंधित पेज
Solingo पर इस concept को practice करें
Library को interactive exercises और integrated IDE के साथ master करें।
मुफ्त में शुरू करें