Created
November 13, 2019 17:20
-
-
Save ernestognw/6446274b5ec183cd282ca76a87dfcc20 to your computer and use it in GitHub Desktop.
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.5.11; | |
contract BBVACoin { | |
// Variables | |
string public name; | |
string public symbol; | |
uint256 public totalSupply; | |
mapping(address => uint256) public balanceOf; | |
mapping(address => mapping(address => uint256)) public allowance; | |
address public owner; | |
// Eventos | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
// Constructor | |
constructor(uint256 _totalSupply, string memory _name, string memory _symbol) public { | |
totalSupply = _totalSupply; | |
name = _name; | |
symbol = _symbol; | |
owner = msg.sender; | |
balanceOf[owner] = totalSupply; | |
} | |
// Metodos | |
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){ | |
uint256 allowedQty = allowance[_from][msg.sender]; | |
require(balanceOf[_from] >= _value && allowedQty >= _value); | |
allowance[_from][msg.sender] -= _value; | |
balanceOf[_from] -= _value; | |
balanceOf[_to] += _value; | |
emit Transfer(_from, _to, _value); | |
return true; | |
} | |
function approve(address _spender, uint256 _value) public returns (bool success){ | |
allowance[msg.sender][_spender] = _value; | |
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