pragma solidity >=0.5.0 < 0.6.0;
import "./Owned.sol";
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
interface ERC20Interface {
function totalSupply() external view returns (uint);
function balanceOf(address _owner) external view returns (uint balance);
function allowance(address _owner, address _spender) external view returns (uint remaining);
function transfer(address _to, uint _tokens) external returns (bool success);
function approve(address _spender, uint _tokens) external returns (bool success);
function transferFrom(address _from, address _to, uint _tokens) external returns (bool success);
event Transfer(address indexed _from, address indexed _to, uint _tokens);
event Approval(address indexed _owner, address indexed _spender, uint _tokens);
}
contract LeadToken is ERC20Interface, Owned {
using SafeMath for uint;
// Public variables of the LeadToken
string public name = "LeadToken";
string public symbol = "LEAD";
string public standard = "Lead Token v1.0";
uint8 public decimals = 18;
uint private _totalSupply;
// Generates a public event on the blockchain that will notify clients
event Transfer(
address indexed _from,
address indexed _to,
uint _value
);
// This notifies clients about the amount burnt
event Burn(
address indexed from,
uint value
);
// Generates a public event on the blockchain that will notify clients
event Approval(
address indexed _owner,
address indexed _spender,
uint _value
);
// This creates an array with all balances
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
/**
* Constructor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
constructor(uint _initialSupply) public {
_totalSupply = _initialSupply * 10 ** uint(decimals);
balances[msg.sender] = _totalSupply;
emit Transfer(address(0x0), msg.sender, _totalSupply);
}
function totalSupply() external view returns (uint) {
return _totalSupply;
}
/**
* Internal transfer, can only be called by this contract
*/
function _transfer(address _from, address _to, uint _value) internal {
require(_to != address(0x0));
require(balances[_from] >= _value);
require(balances[_to].add(_value) >= balances[_to]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(_from, _to, _value);
}
/**
* Transfer tokens
*
* Send `_value` tokens to `_to` from your account
*
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transfer(address _to, uint _value) public returns(bool success){
_transfer(msg.sender, _to, _value);
return true;
}
/**
* Transfer tokens from other address
*
* Send `_value` tokens to `_to` in behalf of `_from`
*
* @param _from The address of the sender
* @param _to The address of the recipient
* @param _value the amount to send
*/
function transferFrom(address _from, address _to, uint _value) public returns (bool success) {
require(_value <= allowed[_from][msg.sender]);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
_transfer(_from, _to, _value);
return true;
}
/**
* Set allowance for other address
*
* Allows `_spender` to spend no more than `_value` tokens in your behalf
*
* @param _spender The address authorized to spend
* @param _value the max amount they can spend
*/
function approve(address _spender, uint _value) public returns (bool success) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* Returns the amount of tokens approved by the owner that can be transferred to the spender's account
*/
function allowance(address _owner, address _spender) public view returns (uint remaining) {
return allowed[_owner][_spender];
}
/**
* Get the token balance for account `tokenOwner`
*/
function balanceOf(address _owner) public view returns (uint balance) {
return balances[_owner];
}
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address _account, uint256 _amount) internal {
require(_account != address(0x0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(_amount);
balances[_account] = balances[_account].add(_amount);
emit Transfer(address(0), _account, _amount);
}
/**
* Destroy tokens
*
* Remove `_value` tokens from the system irreversibly
*
* @param _value is the amount of token to burn
*/
function burn(uint _value) public returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] = balances[msg.sender].sub(_value);
_totalSupply = _totalSupply.sub(_value);
emit Burn(msg.sender, _value);
return true;
}
/**
* Destroy tokens from other account
*
* Remove `_value` tokens from the system irreversibly on behalf of `_from`.
*
* @param _from the address of the sender
* @param _value the amount of money to burn
*/
function burnFrom(address _from, uint _value) public returns (bool success) {
require(balances[_from] >= _value);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
_totalSupply = _totalSupply.sub(_value);
emit Burn(_from, _value);
return true;
}
/**
* Owner can transfer out any accidentally sent ERC20 tokens
*/
function transferAnyERC20Token(address _tokenAddress, uint _tokens) public onlyOwner returns (bool success) {
return ERC20Interface(_tokenAddress).transfer(owner, _tokens);
}
}
1 Like
Please see the Remix documentation for importing: https://remix-ide.readthedocs.io/en/latest/import.html
If you wanted to import OpenZeppelin Contracts in Remix, please see the following simple token example: