Created
October 6, 2022 08:11
-
-
Save PowerStream3604/92be42b955ce5279c5728b524249a243 to your computer and use it in GitHub Desktop.
Example Solidity Smart Contract for Immutable StarkNet Course
This file contains hidden or 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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.13; | |
interface IERC20 { | |
function totalSupply() external view returns (uint); | |
function balanceOf(address account) external view returns (uint); | |
function transfer(address recipient, uint amount) external returns (bool); | |
function allowance(address owner, address spender) external view returns (uint); | |
function approve(address spender, uint amount) external returns (bool); | |
function transferFrom( | |
address sender, | |
address recipient, | |
uint amount | |
) external returns (bool); | |
event Transfer(address indexed from, address indexed to, uint value); | |
event Approval(address indexed owner, address indexed spender, uint value); | |
} | |
contract ERC20 is IERC20 { | |
uint public totalSupply; | |
mapping(address => uint) public balanceOf; | |
mapping(address => mapping(address => uint)) public allowance; | |
string public name = "Immutable StarkNet Course"; | |
string public symbol = "ISC"; | |
uint8 public decimals = 18; | |
function transfer(address recipient, uint amount) external returns (bool) { | |
balanceOf[msg.sender] -= amount; | |
balanceOf[recipient] += amount; | |
emit Transfer(msg.sender, recipient, amount); | |
return true; | |
} | |
function approve(address spender, uint amount) external returns (bool) { | |
allowance[msg.sender][spender] = amount; | |
emit Approval(msg.sender, spender, amount); | |
return true; | |
} | |
function transferFrom( | |
address sender, | |
address recipient, | |
uint amount | |
) external returns (bool) { | |
allowance[sender][msg.sender] -= amount; | |
balanceOf[sender] -= amount; | |
balanceOf[recipient] += amount; | |
emit Transfer(sender, recipient, amount); | |
return true; | |
} | |
function mint(uint amount) external { | |
balanceOf[msg.sender] += amount; | |
totalSupply += amount; | |
emit Transfer(address(0), msg.sender, amount); | |
} | |
function burn(uint amount) external { | |
balanceOf[msg.sender] -= amount; | |
totalSupply -= amount; | |
emit Transfer(msg.sender, address(0), amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment