0

I am trying to figure out what is wrong with the following code as it does deploy successfully on remix.

pragma solidity ^0.6.7;

import "./ERCI20.sol"; // ERC20 token interface
import "./SafeMath.sol"; // openzepplin safemath library

contract TimeBound is ERCI20 {

using SafeMath for uint256;
address public contractOwner;

mapping (address => uint256) private Balances;
mapping (address => mapping (address => uint256)) private Allowances;

uint256 private _totalSupply;

string public name;
string public symbol;
uint8 public decimals;

uint256 public releaseTime;

event releaseTimeSet(bool success, uint256 time);

modifier onlyOwner() {
    require(msg.sender == contractOwner, "TB9Token: Only owner allowed");
    _;
}
modifier TimeLock() {
    require(block.timestamp >= releaseTime, "TB9Token: Token is locked for certain Time");
    _;
}


constructor() public {
    name = "TimeBound Token";
    symbol = "TB9Token";
    decimals = 0;
    contractOwner = msg.sender;

    _totalSupply = 1000000 * (10 ** uint256(decimals));

    Balances[contractOwner] = _totalSupply;

    emit Transfer(address(this), contractOwner, _totalSupply);
}

function totalSupply() external view override returns(uint256) {
    return _totalSupply;
}

function balanceOf(address account) external view override returns(uint256) {
    return Balances[account]; 
}

function transfer(address recipient, uint256 amount) external override TimeLock() returns(bool) {
    address sender = msg.sender;

    require(sender != address(0), "TB9Token:should not transfer from the zero address");
    require(recipient != address(0), "TB9Token:should not transfer to the zero address");
    require(Balances[sender] > amount);

    Balances[sender] = Balances[sender].sub(amount); 

    Balances[recipient] = Balances[recipient].add(amount);

    emit Transfer(sender, recipient, amount);
    return true;
}
function allowance(address tokenOwner, address spender) external view override returns(uint256) {
    return Allowances[tokenOwner][spender];
} 
function approve(address spender, uint256 amount) external override returns(bool) {
    address tokenOwner = msg.sender;

    require(tokenOwner != address(0), "TB9Token: should not approve from the zero address");
    require(spender != address(0), "TB9Token:should not approve to the zero address");

    Allowances[tokenOwner][spender] = amount;

    emit Approval(tokenOwner, spender, amount);
    return true;
}

function transferFrom(address sender, address recipient, uint256 amount) external override TimeLock() returns(bool) {
    address spender = msg.sender;
    uint256 Allowance = Allowances[sender][spender];

    require(sender != address(0), "TB9Token:should not transfer from the zero address");
    require(recipient != address(0), "TB9Token:should not transfer to the zero address");
    require(Balances[sender] > amount, "TB9Token: transfer amount exceeds");
    require(Allowance > amount, "TB9Token: transfer amount exceeds allowance");

    Allowance = Allowance.sub(amount);

    Balances[recipient] = Balances[recipient].add(amount);

    Balances[sender] =Balances[sender].sub(amount); 

    emit Transfer(sender, recipient, amount);
    Allowances[sender][spender] = Allowance;

    emit Approval(sender, spender, amount);

    return true;
}
function setReleaseTime(uint _releaseTime) public onlyOwner() returns(bool) {
    require(_releaseTime > block.timestamp, "TB9Token: releaseTime must be valid in the future");

    releaseTime = _releaseTime;

    emit releaseTimeSet(true, _releaseTime);

    return true;
}

}

i am deploying this code timeBound contract first on ropsten testnetwork using metamask. timeBound contract deploys successfully then i/m calling the following functions:

  1. First i call the function setReleaseTime and put time in seconds unix time. setReleaseTime call successfully and i can see a transaction in my metamask.

  2. Second i call transfer function and provide recipent address and amount.

as i call transfer function remix show me a pop up, this one **Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? gas required exceeds allowance (8000029) or always failing transaction**

enter image description here

may be i am calling wrong function first, please help me to resolve this issue

6
  • Where are you deploying, a public testnet a private testnet? Likely one of the requires is failing.
    – Ismael
    May 16, 2020 at 3:14
  • See my comments to this similar question. May 16, 2020 at 7:22
  • BTW, with regards to require(Balances[sender] > amount): 1. You probably want to use >= here. 2. Is the balance of the sender really larger than the amount that you are passing as input? May 16, 2020 at 9:20
  • @Ismael i'm deploying it on ropsten with metamask and remix
    – sultan
    May 16, 2020 at 9:53
  • @goodvibration i'll try. maybe i'm calling first the releaseTime function then i call transfer function, if the releaseTime function execute earlier and then transfer function executes, it might produce time error, but i gives Gas estimation error, which is unbelevieable
    – sultan
    May 16, 2020 at 9:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.