Created
December 9, 2020 03:09
-
-
Save combattardigrade/df3ee2519cd70e606198909e7146d9ec to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.6+commit.6c089d02.js&optimize=false&runs=200&gist=
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
pragma solidity >=0.6.0 <0.8.0; | |
// SPDX-License-Identifier: MIT" | |
contract Token { | |
mapping (address => uint256) private _balances; | |
uint256 private _totalSupply; | |
string private _name; | |
string private _symbol; | |
uint256 private _decimals; | |
uint256 private theTotalSupply; | |
constructor(string memory name, string memory symbol) public { | |
// _name = "Test"; | |
// _symbol = "TEST"; | |
// _decimals = 18; | |
// _totalSupply = 0; | |
// Assign temporal variables to contract variables | |
// https://docs.soliditylang.org/en/v0.5.3/contracts.html | |
_name = name; | |
_symbol = symbol; | |
// You can assign the total number of token in circulation here | |
// Solidity does not have decimal values so they are represented in integers | |
// The standard is to repredent balances in wei units | |
// https://eth-converter.com/ | |
_totalSupply = 1000e18; // = 1000 tokens in wei units (18 decimals) | |
// Add balance to msg.sender, the Ethereum account that deployed the contract | |
_balances[msg.sender] = 1000e18; | |
// The ERC20 tokens have 18 decimals | |
_decimals = 18; | |
} | |
/** | |
* @dev Returns the name of the token | |
*/ | |
function name() public view returns (string memory) { | |
return _name; | |
} | |
/** | |
* @dev Set the name of the token | |
*/ | |
function setName(string memory name) public { | |
_name = name; | |
} | |
/** | |
* | |
* @dev Returns the symbol of the token | |
*/ | |
// function symbol() public view returns (string) { | |
// You need to add the keyword `memory` to temporal strings | |
function symbol() public view returns (string memory) { | |
return _symbol; | |
} | |
/** | |
* @dev Returns the decimals of the token | |
*/ | |
// function decimals() public view returns (uint8) { | |
// The returned value does not match `_decimals` data type since it's of type uint256 | |
// and you are trying to return a uint8 | |
function decimals() public view returns (uint256) { | |
return _decimals; | |
} | |
/** | |
* @dev Returns the total supply of the token | |
*/ | |
function totalSupply() public view returns (uint256) { | |
// This function should return the totalSupply or amount of tokens in circulation | |
// so you don't need to assign anything | |
// theTotalSupply = _totalSupply; | |
return theTotalSupply; | |
} | |
/** | |
* @dev Returns the balance of the token | |
*/ | |
function balanceOf(address _owner) public view returns (uint256) { | |
// You are missing an `s` | |
// return balance[_owner]; | |
return _balances[_owner]; | |
} | |
/** | |
* @dev Returns the transfer of the token | |
*/ | |
function transfer(address _to, uint256 _value) public returns (bool success) { | |
_balances[msg.sender] -= _value; | |
_balances[_to] += _value; | |
// This is not necessary or maybe you are trying to emit an Event | |
// https://docs.soliditylang.org/en/v0.6.7/contracts.html#events | |
// transfer(msg.sender, _to, _value); // | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
// Declare event | |
event Transfer(address sender, address recipient, uint256 amount); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment