How to use TokenTimelock.sol to lock up tokens?

Hello wonderful people!

I am not a developer but I managed to use openzeppelin to create my first erc20 token for my game project! it’s working wonderfully.

This is a wonderful project! Many thanks for all contributors :blush:

I want to use TokenTimelock.sol to create a new contract so that I can send some tokens to it to lock them up for a specific time

here’s my tokenlockup.sol file:

pragma solidity ^0.5.2;

import "openzeppelin-solidity/contracts/token/ERC20/TokenTimelock.sol";


contract lockupMyTokens {
  string public constant token = "0xmytokenaddress";
  string public constant beneficiary = "0xmyBeneficiaryAddress";
  // Test May 28th 8:30 pm GNT
  uint256 public constant releaseTime = 1559075400;
}

I deployed it to testnet but I cannot interact with the contract. I think I need to add some function or constructor.

Can anyone help me to add this missing piece?

I looked at all github issues / PRs and couldn’t find an example that I can copy paste and use because I don’t have much dev experience, I couldn’t figure this out and it’s been 2 days now.

Any help would be appreciated!

2 Likes

Hi @manipulator01
Welcome to the forum. It would be great if you could take a moment and Introduce yourself here! including a bit more about the game you are working on.

A TokenTimelock contract could look as follows:
What you didn’t have was inheriting from TokenTimelock (is TokenTimelock) and calling the TokenTimelock constructor with your desired values.

Once deployed, as you said, you would need to transfer the tokens to the timelock contract.

pragma solidity ^0.5.2;

import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/TokenTimelock.sol";


contract SimpleTokenTimelock is TokenTimelock {
    constructor () public TokenTimelock(
        IERC20(0xCfEB869F69431e42cdB54A4F4f105C19C080A601), // token
        0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b, // beneficiary
        1559075400) {
    }
}

If there isn’t an example, the tests can be good to look at to work out how a contract works. Though please ask all the questions that you need.

2 Likes

Note that it’s not necessary to use inheritance to define the constructor arguments.

If you’re using a Truffle/web3.js contract, for example you can pass arguments as TokenTimelock.new(token, beneficiary, release). If you’re using Truffle migrations, I think you can do deployer.deploy(TokenTimelock, token, beneficiary, release).

2 Likes

Thank you so much @abcoathup! It worked like a charm. :heart_eyes:
@frangio thanks for the advice. I didn’t know I can do that.

You guys are awesome. :slightly_smiling_face:

3 Likes

Hi @manipulator01 when you have a moment it would be awesome if you could Introduce yourself here! and/or let us know What are you working on?

1 Like