0

I am trying to learn how to make my own token. I want to add a timelock so that tokens that are purchased can not be sold until a specific time. How would I go about this? I have very very little coding knowledge, so I am pretty lost. I watched a video on youtube and got this code:

pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";

contract J4RK0FF is ERC20 {
    constructor(uint256 initialSupply) public ERC20("J4RK0FF", "J4RK") {
        _mint(msg.sender, initialSupply);
    }

}

So if this works as a basic unmodified contract, how can I add a timelock feature to it? Thanks in advance, sorry if I sound stupid, I have no idea what I am doing

1
  • Check the online manual at docs.soliditylang.org/en/v0.8.4 or later version. Then under "Units and Globally Available Variables" there is a block.timestamp variable. You can set a contract variable representing some time in the future, and check if block.timestamp > timelock from within your transfer() function.
    – bitsanity
    Apr 29, 2021 at 1:58

1 Answer 1

0

One solution is to create a mapping (address => uint256) timelock where for each account you specify the timestamp when the tokens will be unlocked.

Then you can add more complexity instead of specifying a single timestamp use an array of dates allowing partials unlocks if you purchase tokes at different times.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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