Created
July 29, 2021 02:02
-
-
Save marcomu/c5faca351aa8025ce99e27c4c0dab52d to your computer and use it in GitHub Desktop.
Token ERC20
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.4.24; | |
contract ERC20{ | |
string public name = "BAM Coin"; | |
string public symbol = "BAM"; | |
uint256 public totalSupply; | |
mapping(address => uint256) public balanceOf; | |
mapping(address => mapping(address => uint256)) public allowance; | |
event Transfer( | |
address indexed _from, | |
address indexed _to, | |
uint256 _value | |
); | |
event Approval( | |
address indexed _owner, | |
address indexed _spender, | |
uint256 _value | |
); | |
//LA PRIMER FUNCION QUE EJECUTA LA EVM AL DESPLEGAR EL TOKEN | |
constructor(uint256 _initialSupply)public { | |
balanceOf[msg.sender] = _initialSupply; | |
totalSupply = _initialSupply; | |
} | |
function transfer(address _to, uint256 _value) public returns(bool success){ | |
require(balanceOf[msg.sender] >= _value); | |
balanceOf[msg.sender] -= _value; | |
balanceOf[_to] += _value; | |
emit Transfer(msg.sender,_to,_value); | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns(bool success){ | |
//Validar que lo que quiere mandar es menor a su saldo | |
require(_value <= balanceOf[_from]); | |
//Validar que le permitieron gastar lo suficiente | |
require(_value <= allowance[_from][msg.sender]); | |
balanceOf[_from] -= _value; | |
balanceOf[_to] += _value; | |
emit Transfer(_from, _to, _value); | |
return true; | |
} | |
function approve(address _spender, uint _value) public returns(bool success){ | |
allowance[msg.sender][_spender] = _value; | |
// Ejecutamos el evento como approval | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Link hacia Remix: https://remix.ethereum.org