Skip to content

Instantly share code, notes, and snippets.

@hughpearse
Last active December 15, 2023 12:37
Show Gist options
  • Save hughpearse/d03f00b5fd7683ed5015c8bed91e5b25 to your computer and use it in GitHub Desktop.
Save hughpearse/d03f00b5fd7683ed5015c8bed91e5b25 to your computer and use it in GitHub Desktop.
Openzeppelin solidity smart contract for HughCoin tokens pegged to ETH
// SPDX-License-Identifier: MIT
// Author: Hugh Pearse
pragma solidity ^0.8.20;
import {ERC20} from "@openzeppelin/contracts@5.0.1/token/ERC20/ERC20.sol";
/// @custom:security-contact hughpearse@gmail.com
contract HughCoin is ERC20 {
address public owner;
constructor()
ERC20("HughCoin", "HUGH")
{
owner = msg.sender;
}
function deposit() public payable {
require(msg.value > 0, "Deposit value must be greater than 0");
_mint(msg.sender, msg.value);
}
function withdraw(uint256 amount) public {
require(balanceOf(msg.sender) >= amount, "Not enough tokens to withdraw");
_burn(msg.sender, amount);
payable(msg.sender).transfer(amount);
}
receive() external payable {
deposit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment