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.

sultan
  • 265
  • 1
  • 3
  • 12
  • 2
    balanceOf is expecting an address not the amount in uint – niksmac May 07 '20 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 07 '20 at 12:09
  • Use functions supported in the solidity version you are using – niksmac May 07 '20 at 12:10
  • right, we are using balanceOf property to find token balance? – sultan May 07 '20 at 12:13
  • 2
    balanceOf can be used to find the token balance and address(this).balance to get ETH balance – niksmac May 07 '20 at 12:14
  • i can't find the reason behind this, it is still showing that error while i'm applying all the possible methods. – sultan May 07 '20 at 12:23
  • ok @niksmac can you tell me why to use newERC20, this is the ERC20 interface, and if i not import it in this code, so the code will executed properly? – sultan May 07 '20 at 12:29
  • Regardless of what you're hoping to achieve with uint amount = token.balanceOf(amount), it is incorrect by any programming standard (Solidity or other), as you are attempting to use the variable amount while declaring it! – goodvibration May 07 '20 at 12:46
  • try using: address(this) refer : https://ethereum.stackexchange.com/questions/2806/how-do-you-refer-to-a-contract-own-address-inside-it – Marcos Lobo Jun 16 '22 at 21:54

1 Answers1

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.

goodvibration
  • 26,003
  • 5
  • 46
  • 86
  • 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 07 '20 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.
    3. how i'll mention the releaseTime = now + 600 seconds? OR releaseTime = block.timeStamp + 600 seconds?

    please provide guidence...

    – sultan May 07 '20 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. – goodvibration May 07 '20 at 15:27