Created
November 10, 2021 01:57
-
-
Save JackBekket/a830e963edaf60d6db8612d2ad229d84 to your computer and use it in GitHub Desktop.
example 2
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(msg.sender, msg.value); | |
} | |
function sell(address whoToSend, uint256 ntcToMint) payable public { | |
address owner_ = owner(); | |
Neetcoin.mint(whoToSend, ntcToMint); | |
bool sent = owner_.send(ntcToMint); | |
require(sent, "Failed to send Ether"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment