Loading...
What is Smart Contract?
Smart contracts are simply programs stored on a blockchain that run when predetermined conditions are met. They typically are used to automate the execution of an agreement so that all participants can be immediately certain of the outcome, without any intermediary’s involvement or time loss. They can also automate a workflow, triggering the next action when conditions are met.
What are Tokens ?
In general, a token is an object that represents something else, such as another object (either physical or virtual), or an abstract concept as, for example, a gift is sometimes referred to as a token of the giver's esteem for the recipient. In computers, there are a number of types of tokens.
What is ERC20 Tokens ?
ERC-20 tokens are set of standards for fungible tokens that have the property that makes each and every tokens exactly the same(in type and value). For example, an ERC-20 Token acts just like the ETH, meaning that 1 Token is and will always be equal to all the other Tokens.
pragma solidity ^0.8.5;
interface tokenRecipient { function receiveApproval(address _from, uint _value, address _token, bytes memory _extraData) external;}
contract owned {
address public owner;
constructor(){
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
}
contract TokenERC20 is owned {
string public name;
string public symbol;
uint8 public decimals = 18;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint)) public allowance;
constructor() {
totalSupply = 10000*10**uint(decimals);
balanceOf[msg.sender] = totalSupply;
symbol = 'ART';
name = 'ArtCoin';
}
function _transfer(address _from, address _to, uint _value) internal {
require(_to != address(0));
require(balanceOf[_from] >= _value);
require(balanceOf[_to] + _value >= balanceOf[_to]);
uint previousBalances = balanceOf[_from] + balanceOf[_to];
balanceOf[_from] -= _value;
balanceOf[_to] += _value;
assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
}
function _transfer(address _to, uint _value) public returns(bool success) {
_transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint _value) public returns (bool success){
require(_value <= allowance[_from][msg.sender]);
allowance[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
function approve (address _spender, uint _value) public returns (bool success){
allowance[msg.sender][_spender] = _value;
return true;
}
function approveAndCall(address _spender, uint _value, bytes memory _extraData) public returns(bool success){
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, address(this), _extraData);
return true;
}
}
function burn(uint _value) public returns(bool success) {
require(balanceOf[msg.sender] >= _value);
balanceOf[msg.sender]-= _value;
totalSupply -= _value;
return true;
}
function burnFrom(address _from, uint _value) public payable returns(bool success) {
require(balanceOf[_from] >= _value);
require(_value <= allowance[_from][msg.sender]);
balanceOf[_from] -= _value;
totalSupply -= _value;
return true;
}
function mintToken (address target, uint mintedAmount) public onlyOwner {
balanceOf[target] += mintedAmount;
totalSupply += mintedAmount;
}
}