250x250
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 |
Tags
- express.js
- JavaScript
- CSS
- graphQL
- hardhat
- evm
- Props
- Redux
- bitcoin
- useState
- error
- SSR
- typeScript
- Ethereum
- 삶
- node.js
- concept
- middleware
- nextJS
- solidity
- HTML
- web
- 기준
- tailwindcss
- built in object
- API
- CLASS
- Interface
- REACT
- blockchain
Archives
- Today
- Total
ReasonJun
Solidity : deposit code example 본문
728x90
// SPDX-License-Identifier: MIT
pragma solidity >= 0.7.0 < 0.9.0;
contract Bank0 {
// 예금자 주소 => 금액
mapping (address => uint) public balance;
event log(bytes data);
function deposit() public payable returns (uint) {
balance[msg.sender] += msg.value;
return msg.value;
}
function withdrawByCall(address payable _addr, uint _amount) public {
require(balance[msg.sender] > _amount, "Insufficient Balance");
balance[msg.sender] -= _amount;
(bool success, bytes memory data) = _addr.call{value: _amount}("");
// bytes memory data = abi.encodeWithSignature("abcdefg(address, uint)", _addr, _value);
// (bool success, bytes memory data) = _addr.call{value: _amount}(data);
emit log(data);
require(success, "Transfer Failed");
}
function withdrawBySend(address payable _addr, uint _amount) public {
require(balance[msg.sender] > _amount, "Insufficient Balance");
balance[msg.sender] -= _amount;
(bool success) = _addr.send(_amount);
require(success, "Transfer Failed");
}
function withdrawByTransfer(address payable _addr, uint _amount) public {
require(balance[msg.sender] > _amount, "Insufficient Balance");
balance[msg.sender] -= _amount;
_addr.transfer(_amount);
}
function getMyBalance() public view returns(uint) {
return balance[msg.sender];
}
}
728x90
'Blockchain > Solidity' 카테고리의 다른 글
Openzeppelin : ERC721PresetMinterPauserAutoId (0) | 2023.10.22 |
---|---|
Solidity : sol2uml (0) | 2023.10.20 |
Solidity : fallback() vs receive() (0) | 2023.10.18 |
Solidity : receive() (0) | 2023.10.18 |
Solidity : call() vs delegatecall() (0) | 2023.10.18 |
Comments