Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- web3.js
- ERC721
- 블록체인
- 노마드코더
- 이더리움
- Non-Blocking
- ETH
- 솔리디티
- it5분잡학사전
- 페이지클론
- 정보처리기사
- 정보처리기사실기요약
- it5
- npm
- 카카오페이지클론
- ERC-721
- 콜백함수this
- github
- 노개북
- React
- 비트코인
- git
- 2021정보처리기사실기
- Klaytn
- 카카오홈페이지클론
- 정보처리기사실기
- solidity
- blockchain
- 클레이튼
- node.js
Archives
- Today
- Total
Be lazy, Be crazy
Error 본문
728x90
반응형
솔리디티에서 error을 작성할 수 있는 몇가지에 대해서 코드로 봐보자!
여기서 나도 처음 보았던 것은 error를 커스텀 할 수 있다는것이다.
error MyError(address caller, uint value); 이런식으로 말이다.
자세한 내용은 밑에 코드를 보고 remix에서 실행시켜보면 이해가 될 것이다.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
//require, revert, assert
// gas refund, state updates are reverted
// custom error - save gas
contract Error {
function testRequire(uint _i) public pure{
require(_i < 10, "i > 10");
}
//revert는 검사할 조건이 많은 if문에 중첩되어 있는 경우에 더 나은 옵션이 될수가 있다.
function testRevert(uint _i) public pure {
if(_i > 10){
if(_i > 2){
if(_i > 10){
revert("i>10");
}
}
}
}
uint public num = 123;
function testAssert() public view {
assert(num == 123);
}
function foo() public {
num++;
}
//사용자 지정 에러를 사용하는이유는 메세지가 길면길수록 require보다 저렴하다는 것이다.
error MyError(address caller, uint i);
function testCustomerError(uint _i) public view {
if(_i > 10){
revert MyError(msg.sender, _i);
}
}
}
반응형
'BlockChain > 솔리디티' 카테고리의 다른 글
Array (0) | 2022.03.15 |
---|---|
FunctionOutputs (0) | 2022.03.14 |
FunctionModifier (1) | 2022.03.13 |
ForAndWhileLoops (2) | 2022.03.12 |
If Else (0) | 2022.03.12 |
Comments