Skip to content

Instantly share code, notes, and snippets.

@evan-moon
Created November 9, 2021 12:59
Show Gist options
  • Save evan-moon/42adc56149c4039498027553c3667a91 to your computer and use it in GitHub Desktop.
Save evan-moon/42adc56149c4039498027553c3667a91 to your computer and use it in GitHub Desktop.
솔리디티 연습
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