티스토리 뷰
728x90
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.11;
contract MoneyBox {
address owner;
mapping (uint256 => mapping(address => bool)) memberList;
uint256 round = 1;
constructor() {
owner = msg.sender;
}
receive() external payable {
require(msg.value == 0.1 ether, "Must be 0.1 Ether.");
require(memberList[round][msg.sender] == false, "You are joined already.");
memberList[round][msg.sender] = true;
if (address(this).balance == 0.3 ether) {
(bool sent,)= payable(msg.sender).call{value:address(this).balance}("");
require(sent,"Failed.");
round++;
}
}
function checkRound() public view returns(uint256){
return round;
}
function checkValue() public view returns(uint256){
require(owner==msg.sender, "You are not owner.");
return address(this).balance;
}
}
require(memberList[round][msg.sender] == false, "You are joined already.");
위 코드를 아래처럼 작성하면 out of gas 에러가 났다. 아래처럼 작성하면 트랜잭션을 보낼 때 gas 한도가 21000으로 고정이 되었다. memberList[round][msg.sender]
즉, mapping 타입에서 특정 주소 값을 아직 true로 설정해놓지 않았다면(mapping에서 key가 특정 주소인 value가 존재하지 않으면) false를 리턴하길래 아래처럼 코드를 작성해도 동작할 줄 알았지만 정상 동작하지 않았다.
require(memberList[round][msg.sender], "You are joined already.");
'블록체인 개발 > Solidity' 카테고리의 다른 글
Upgradable Contracts 1 (Proxy Pattern) (0) | 2022.04.03 |
---|---|
interface (0) | 2022.01.02 |
call (0) | 2022.01.02 |
fallback, receive (0) | 2022.01.02 |
send, transfer, call (0) | 2022.01.02 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- class
- 이더리움
- Flutter
- web3.js
- nft
- avalanchego
- JWT
- Android
- ethers.js
- ganache
- 스마트 컨트랙트
- web3-token
- 블록 탐색기
- caver-js
- metamask-extension
- eslint
- caver.js
- 앱 아이콘
- swr
- 블록체인
- Proxy Pattern
- interface
- Call
- Hardhat
- Truffle
- web3
- erc20
- Upgradeable Contracts
- ERC721
- typescript
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함