Created
December 13, 2022 04:53
-
-
Save ofou/ef3d7e47c85ca39df6c59ac9e7a815c0 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.17+commit.8df45f5f.js&optimize=false&runs=200&gist=
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
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.17; | |
pragma experimental ABIEncoderV2; | |
interface MyTokenInterfaces { | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address _tokenOwner) external view returns (uint256); | |
function allowance(address _owner, address _spender) | |
external | |
view | |
returns (uint256); | |
function transfer(address _recipient, uint256 _amount) | |
external | |
returns (bool); | |
function approve(address _spender, uint256 _amount) external returns (bool); | |
function transferFrom( | |
address _owner, | |
address _buyer, | |
uint256 _amount | |
) external returns (bool); | |
function increaseTotalSupply( | |
uint _newTokensAmount | |
) external returns (bool); | |
} | |
contract MyToken is MyTokenInterfaces { | |
string public constant name = unicode"Introducción a Blockchain"; | |
string public constant symbol = "IBTOK"; | |
uint8 public constant decimals = 18; | |
uint256 private totalSupply_; | |
mapping(address => uint256) balances; | |
mapping(address => mapping(address => uint256)) allowed; | |
event Transfer(address indexed _from, address indexed _to, uint256 _amount); | |
event Approval( | |
address indexed _owner, | |
address indexed _spender, | |
uint256 _amount | |
); | |
constructor(uint256 _initialSupply) { | |
totalSupply_ = _initialSupply; | |
balances[msg.sender] = totalSupply_; | |
} | |
function totalSupply() public view override returns (uint256) { | |
return totalSupply_; | |
} | |
function balanceOf(address _tokenOwner) | |
public | |
view | |
override | |
returns (uint256) | |
{ | |
return balances[_tokenOwner]; | |
} | |
function allowance(address _owner, address _spender) | |
public | |
view | |
override | |
returns (uint256) | |
{ | |
return allowed[_owner][_spender]; | |
} | |
function transfer(address _recipient, uint256 _amount) | |
public | |
override | |
returns (bool) | |
{ | |
require(_amount <= balances[msg.sender]); | |
balances[msg.sender] -= _amount; | |
balances[_recipient] += _amount; | |
emit Transfer(msg.sender, _recipient, _amount); | |
return true; | |
} | |
function approve(address _spender, uint256 _amount) | |
public | |
override | |
returns (bool) | |
{ | |
allowed[msg.sender][_spender] = _amount; | |
emit Approval(msg.sender, _spender, _amount); | |
return true; | |
} | |
function transferFrom( | |
address _owner, | |
address _buyer, | |
uint256 _amount | |
) public override returns (bool) { | |
require(_amount <= balances[_owner]); | |
require(_amount <= allowed[_owner][msg.sender]); | |
balances[_owner] -= _amount; | |
allowed[_owner][msg.sender] -= _amount; | |
balances[_buyer] += _amount; | |
emit Transfer(_owner, _buyer, _amount); | |
return true; | |
} | |
function increaseTotalSupply(uint _newTokensAmount) public override returns (bool) { | |
totalSupply_ += _newTokensAmount; | |
balances[msg.sender] += _newTokensAmount; | |
return true; | |
} | |
// Test | |
// Hugo (creador del token): 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4 | |
// Paco (Tenedor de tokens): 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2 | |
// Luis (spender): 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment