I have been searching the web for a simple/safe ERC-20 Token Bare-Bone Contract example to use as a base for learning. The Bare-Bones as I understand would only include what the ERC-20 Token Standard requires it to:
function totalSupply() public constant returns (uint);
function balanceOf(address tokenOwner) public constant returns (uint balance);
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
sources: https://theethereum.wiki/w/index.php/ERC20_Token_Standard , https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
However, even when finding simple templates, you find differences, for instance:
includes the burn(...)
and burnFrom(...)
functions. At first glance, all that might need to be done is delete these two. However when looking at another example:
there was the inclusion of various other portions of code that at first glance might seem vital for the ERC-20 standard (but I'm unsure), for instance:
// ----------------------------------------------------------------------------
// Safe maths
// ----------------------------------------------------------------------------
contract SafeMath {
function safeAdd(uint a, uint b) public pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) public pure returns (uint c) {
require(b <= a);
c = a - b;
}
function safeMul(uint a, uint b) public pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function safeDiv(uint a, uint b) public pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public constant returns (uint);
function balanceOf(address tokenOwner) public constant returns (uint balance);
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
QUESTIONS:
Is the SafeMaths section preventing some types of hacks/exploits? And if that were the case, why don't I see something as important as this in other token examples? Also I'm unsure why another contract called ERC20Interface
is being made that initiates the functions, is it just for organization purposes?
If someone has a better simple BARE-BONES template, please do sure! Thank you.