- 不能存在状态变量
- 不能够继承和被继承
- 不能接受以太币
- 不可以被销毁
- 库合约的可见效为public或者external时,为delegatecall调用
- 使用using for 指令
// 利用using for指令
using Strings for uint256;
function getString1(uint256 _number) public pure returns(string memory){
// 库合约中的函数会自动添加为uint256型变量的成员
return _number.toHexString();
}
- 通过库合约名称调用函数
// 直接通过库合约名调用
function getString2(uint256 _number) public pure returns(string memory){
return Strings.toHexString(_number);
}
- Strings:将uint256转换为String
- Address:判断某个地址是否为合约地址
- Create2:更安全的使用Create2 EVM opcode
- Arrays:跟数组相关的库合约
文件结构
├── Import.sol
└── Yeye.sol
// 通过文件相对位置import
import './Yeye.sol';
// 通过网址引用
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Address.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import {Yeye} from './Yeye.sol';