Created
November 10, 2021 01:54
-
-
Save JackBekket/eabc569f2be4de0f0b5cbf71fe6d04de to your computer and use it in GitHub Desktop.
example reciving ether #1
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.9; | |
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
// https://solidity-by-example.org/sending-ether/ | |
contract Neetcoin is ERC20, Ownable { | |
constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) public {} | |
function mint(address account, uint256 amount) public onlyOwner { | |
_mint(account, amount); | |
} | |
fallback() external payable { | |
sell(); | |
} | |
function sell() payable public { | |
address owner_ = owner(); | |
address whoToSend = msg.sender; | |
uint256 ntcToMint = msg.value; | |
Neetcoin.mint(whoToSend, ntcToMint); | |
bool sent = owner_.send(msg.value); | |
require(sent, "Failed to send Ether"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment