1
pragma solidity ^0.6.6;
import "./newERC20.sol";
contract TokenTimelock {

  newERC20 token;
  address beneficiary;
  uint releaseTime;


  function timelock(newERC20 _token, address _beneficiary, uint _releaseTime) public {
    require(_releaseTime > now);
    token = _token;
    beneficiary = _beneficiary;
    releaseTime = _releaseTime;
  }
  function claim() public {
    require(msg.sender == beneficiary);
    require(now >= releaseTime);

    uint amount = token.balanceOf(this);
    // what the purpose of using "uint amount" here, this amount produces an error

    require(amount > 0);

    token.transfer(beneficiary, amount);
  }
}

Or can you share more ways to lock certain amount of tokens and release on a specific time.

9
  • 2
    balanceOf is expecting an address not the amount in uint
    – niksmac
    May 7, 2020 at 12:04
  • ok, if i put 'token.balanceOf(this)' it produces error again, when i change compiler version to 0.4 and 0.5 the error become silent but as i move to 0.6 it pop up again
    – sultan
    May 7, 2020 at 12:09
  • Use functions supported in the solidity version you are using
    – niksmac
    May 7, 2020 at 12:10
  • right, we are using balanceOf property to find token balance?
    – sultan
    May 7, 2020 at 12:13
  • 2
    balanceOf can be used to find the token balance and address(this).balance to get ETH balance
    – niksmac
    May 7, 2020 at 12:14

1 Answer 1

0

Regardless of what you're hoping to achieve with:

uint amount = token.balanceOf(amount);
// what the purpose of using "uint amount" here, this amount produces an error

It is incorrect by any programming standard (Solidity or other).

You are attempting to use the amount variable while declaring it.

3
  • yeah, i know it is incorrect, i correct it to uint amount = token.balanceOf(this) but still having error, when putting (msg.sender) it is correct.
    – sultan
    May 7, 2020 at 14:45
  • what's about variable releaseTime if i want to lock tokens for next 10 minutes what should i do. as i know to do the following: 1. first i need to send tokens from token contract to this timeLock contract. 2. second i will lock tokens in this timeLock contract with the desired address to which i want to send. 2. how i'll mention the releaseTime = now + 600 seconds? OR releaseTime = block.timeStamp + 600 seconds? please provide guidence...
    – sultan
    May 7, 2020 at 14:53
  • @sultan: Your question was about this statement, and I've answered it. If you have a different question then please post it separately. May 7, 2020 at 15:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.