Created
November 9, 2021 12:59
-
-
Save evan-moon/42adc56149c4039498027553c3667a91 to your computer and use it in GitHub Desktop.
솔리디티 연습
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.3; | |
contract MyContract { | |
address payable private owner; | |
uint256 totalTokens; | |
constructor() public payable { | |
owner = payable(msg.sender); | |
totalTokens = 1000000000000; | |
} | |
function getOwner() public view returns(address) { | |
return owner; | |
} | |
function getTotalAmount() public view returns(uint256) { | |
return totalTokens; | |
} | |
function deposit() public payable {} | |
function getBalance () public view returns(uint256) { | |
return address(this).balance; | |
} | |
function withdraw() public { | |
uint amount = address(this).balance; | |
(bool success, ) = owner.call{value: amount}(""); | |
require(success, "Failed to send Ether"); | |
} | |
function transfer(address payable _to, uint256 _amount) public payable { | |
// Note that "to" is declared as payable | |
(bool success, ) = _to.call{value: _amount}( | |
"return string" | |
); | |
require(success, "Failed to send Ether"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment