Last active
November 13, 2020 18:32
-
-
Save aalu1418/6961b1355dea79d4585398232d6f8964 to your computer and use it in GitHub Desktop.
Sample Contract for Space Missions
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.5.0 <0.7.0; | |
contract Coin { | |
string public name; //publicly accessible name paratmer | |
string public symbol; //publicly accessible symbol parameter | |
mapping (address => uint) private balances; //creates a "table" for matching address to token balance | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); //emits a standard ERC-20 Transfer event | |
// function that is called when the smart contract is deployed (sets up the parameters) | |
constructor() public { | |
name = "aalu1418"; //set token name to Discord name | |
symbol = "TEST"; // set token symbol | |
balances[msg.sender] = 10e18; //mint initial balance | |
} | |
//transfer tokens from function caller to address | |
function transfer(address receiver, uint amount) public returns(bool) { | |
require(amount <= balances[msg.sender], "Insufficient balance."); | |
balances[msg.sender] -= amount; | |
balances[receiver] += amount; | |
emit Transfer(msg.sender, receiver, amount); | |
return true; | |
} | |
//get balance of address | |
function balanceOf(address tokenOwner) public view returns(uint balance){ | |
return balances[tokenOwner]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment