-
custom errorBlockChain 2022. 12. 6. 09:45
require
solidity에서 보통 에러를 다룰 때
require(amount+totalSupply()<totalNumber,"total number exceed.");이런 식으로 다룬다.
그런데 실질적으로 이렇게 다루면 가스비가 늘어날 뿐더러 배포하는데도 코드의 크기가 커진다.
에러메세지에도 글자마다 가스비가 든다. 솔리디티 컨트랙트는24576 bytes를 넘으면 배포가 되지 않는다. 그러기에 코드를 줄이려는 노력을 많이 한다.custom error
그래서 solidity 0.8.4버전부터 error()라는 것을 사용할 수 있다.
//SPDX-License-Identifier: MIT pragma solidity ^0.8.4; error Unauthorized; contract Minting { function withdraw() public{ if(msg.sender != owner) revert Unauthorized; } }이런 식으로 쓰는 것이다.