#cotinatech Creando un contrato inteligente en solidity para liberar fondos unas vez pasado un tiempo.

in Comunidad Latina3 years ago


descarga (1).png

Hoy voy a elaborar un contrato inteligente que liberará una cantidad de tokens a una persona (address) una vez superado un tiempo límite para ese retiro.

Contrato Token

pragma solidity ^0.8.6;
contract Token{
string public name="My Token";
string public symbol="TKM";
uint8 public decimals=18;
uint public totalSupply=1000 × 10 ** decimals;
mapping(address => uint) public balanceOf;
mapping(address=> mapping(address=> uint)) public allowances;
event Transfer(address indexed from, address indexed to, uint amount);
event Approve(address indexed from, address indexed spender, uint amount);
event TransferFrom(address indexed from, address indexed to, uint amount);
constructor (){
balanceOf[msg.sender]=totalSupply;
}
function transfer (address receiver, uint amount) public {
require(balanceOf[msg.sender]>= amount);
require(receiver!=address(0));
balanceOf[msg.sender]-=amount;
balanceOf[receiver]+=amount;
emit Transfer(msg.sender, receiver, amount);
}
function approve(address spender, uint amount) public {
allowances[msg.sender][spender]= amount;
emit Approve(msg.sender, spender, amount);
}
function transferFrom(address from, address to,uint amount) public{
require(balanceOf[from]>=amount);
require(allowances[from][msg.sender] >= amount);
balanceOf[from]-=amount;
balanceOf[to]+=amount;
allowances[from][msg.sender]-=amount;
emit TransferFrom(from, to, amount);
}
}

ReleaseToken


pragma solidity ^0.8.6;
import "./Token";
contract ReleaseToken{
Token public token;
uint public releaseTime;
address public beneficiary;
constructor (uint _releaseTime, address _beneficiary, Token _token){
requiere(_releaseTime>block.timestamp);
token=_token;
beneficiary=_beneficiary;
releaseTime=_releaseTime;
}

function release() public {
require(block.timestamp> releaseTime);
require(token.balanceOf(address(this)>0));
token.transfer(beneficiary, balanceOf(address(this));
}
}

Una vez nuestros contratos estén desplegados vamos a transferirle tokens al contrato releaseToken. Para que de esta manera el contrato pueda transferirle esos tokens al beneficiario una vez superado el tiempo de liberación de tokens.

#solidity #smartcontract #ethereum #web3js #BSC #binancesmartchain #ether

Sort:  
Loading...

Hi, @jfdesousa7,

Thank you for your contribution to the Steem ecosystem.


Please consider voting for our witness, setting us as a proxy,
or delegate to @ecosynthesizer to earn 100% of the curation rewards!
3000SP | 4000SP | 5000SP | 10000SP | 100000SP

Coin Marketplace

STEEM 0.22
TRX 0.20
JST 0.034
BTC 91793.75
ETH 3121.53
USDT 1.00
SBD 3.17