Skip to content

Instantly share code, notes, and snippets.

@JackBekket
Created November 10, 2021 01:57
Show Gist options
  • Save JackBekket/a830e963edaf60d6db8612d2ad229d84 to your computer and use it in GitHub Desktop.
Save JackBekket/a830e963edaf60d6db8612d2ad229d84 to your computer and use it in GitHub Desktop.
example 2
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