能不用 openzeppelin 就不用 openzeppelin
比如書く一个访问控制和所有权转移
1. 自己書くロジック
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract test {
address owner;
uint256 x;
constructor() {
owner = msg.sender;
}
modifier onlyOwer() {
require(msg.sender == owner);
_;
}
function setOwner(address owner_)public onlyOwer{
owner=owner_;
}
function add ()public onlyOwer {
x=x+1;
}
}
2.openzeppelin を使う
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
contract test is Ownable {
uint256 x;
constructor() {}
function add ()public onlyOwner {
x=x+1;
}
}
差は 168235gas ですね、もしメインネットであれば、おおよそ 30 ドル以上かかります、https://www.cryptoneur.xyz/zh/gas-fees-calculator ガス料金計算ウェブサイト