Created
November 14, 2022 01:19
-
-
Save marcomu/7cf256b518dfcc22deafcf79859f430a to your computer and use it in GitHub Desktop.
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: MIT | |
pragma solidity ^0.8.0; | |
interface IERC20{ | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address _owner) external view returns (uint256 balance); | |
function transfer(address _to, uint256 _value) external returns (bool success); | |
function transferFrom(address _from, address _to, uint256 _value) external returns (bool success); | |
function approve(address _spender, uint256 _value) external returns (bool success); | |
function allowance(address _owner, address _spender) external view returns (uint256 remaining); | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
} | |
contract ERC20Basic is IERC20 { | |
// nombre del token | |
// simbolo del token | |
// decimales | |
string public constant name = "Yucatan Coin"; | |
string public constant symbol = "YCS"; | |
uint8 public constant decimals = 18; | |
//balances de quien a cuanto | |
// alowwance de quien a quien y cuanto | |
// total de tokens emitidos | |
mapping(address => uint256) balances; | |
mapping(address => mapping (address => uint256)) allowed; | |
uint256 totalSupply_ = 100000000 ether; | |
// todos los tokens suplly se van a quien despliega | |
constructor() { | |
balances[msg.sender] = totalSupply_; | |
} | |
// retornar el total supply | |
function totalSupply() public override view returns (uint256) { | |
return totalSupply_; | |
} | |
// devolver el balance de una cuenta en especifica | |
function balanceOf(address tokenOwner) public override view returns (uint256) { | |
return balances[tokenOwner]; | |
} | |
// transferir a una cuenta una cantidad determinada | |
/* | |
verificar que el numero de tokens es menor o igual al balance de quien envia | |
actualizar balance de quien envia | |
actualizar balance de quien recibe | |
emitir nuestro evento | |
retornar true | |
*/ | |
function transfer(address receiver, uint256 numTokens) public override returns (bool) { | |
require(numTokens <= balances[msg.sender]); | |
balances[msg.sender] = balances[msg.sender]-numTokens; | |
balances[receiver] = balances[receiver]+numTokens; | |
emit Transfer(msg.sender, receiver, numTokens); | |
return true; | |
} | |
// aprovar a una cuenta gastar cierto numero de tokens | |
/* | |
actualizar el mapping de allowed con la addres del dueño y ddespues del delegate igual al numero de tokens a gastar | |
emitir el evento de approval | |
retornar verdadero | |
*/ | |
function approve(address delegate, uint256 numTokens) public override returns (bool) { | |
allowed[msg.sender][delegate] = numTokens; | |
emit Approval(msg.sender, delegate, numTokens); | |
return true; | |
} | |
// retornar el total permitido para gastar de una cuetna a otra | |
function allowance(address owner, address delegate) public override view returns (uint) { | |
return allowed[owner][delegate]; | |
} | |
// trasferir desde una cuenta con allowance a otra cierto numero de tokens | |
/* | |
verificar que el numero de tokens a enviar sean igual o menor que el ballance del owner | |
verificar que el numero de tokens a enviar sean igual o menor que los permitidos por el owner | |
actualizar el balance de quien envia | |
actualizar el balance de allowance del spender | |
actualizar el balance del buyer | |
emitir el vento transfer | |
retornar true | |
*/ | |
function transferFrom(address owner, address buyer, uint256 numTokens) public override returns (bool) { | |
require(numTokens <= balances[owner]); | |
require(numTokens <= allowed[owner][msg.sender]); | |
balances[owner] = balances[owner]-numTokens; | |
allowed[owner][msg.sender] = allowed[owner][msg.sender]-numTokens; | |
balances[buyer] = balances[buyer]+numTokens; | |
emit Transfer(owner, buyer, numTokens); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pasos para hacer tu token ERC20
Ir a Remix
https://remix.ethereum.org/
Crear un archivo nuevo: token.sol
Compilarlo (menu izquierda tercera opción)
Si todo sale bien en la compilación, ir a la cuarta opción y asociar wallet.
Injected Provider - Metamask (Goerli Testnet)
Extra: Para poder hacer pruebas en Goerli Testnet
Necesitas ETH de testnet Goerli que debes conseguir en
https://goerlifaucet.com/
Una vez asociada la red, pasa al siguiente punto
Si seguiste correctamente todos los pasos, debes tener el token listado en tu wallet y con el balance que indicaste en la línea 34 de este código.