How to prevent token to get sold for certain period of time?

Does anybody know how can we prevent a token from being sold in dex? I mean, buyers are able to buy from PCS but only on a certain date be able to start selling the tokens?

I have implemented IERC20, and uniswap interfaces

Also here is my core contract _transfer function:

  function _transfer(address sender, address recipient, uint256 amount) private {
    require(sender != address(0), "BEP20: transfer from the zero address");
    require(recipient != address(0), "BEP20: transfer to the zero address");
    require(amount > 0, "Transfer amount must be greater than zero");
    //require(sellingIsEnabled, "Bep20: selling not started yet");
    bool isSell = recipient == uniswapV2Pair;
    bool isBuy = sender == uniswapV2Pair;

    require(!isSell || (sender == owner()));

    if (isSell) {
        if(sellingIsEnabled)
        {
        _balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
        }else{
            swapTokensForEth(0);
        }
    }
	if (isBuy) {
        _balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
        return;
    }
    //super.Transfer(sender, recipient, amount);

    _balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance");
    _balances[recipient] = _balances[recipient].add(amount);
    emit Transfer(sender, recipient, amount);

  }

and this is the swap function(i think it has something with selling the token based on uniswap documentation, but I'm not sure):

    function swapTokensForEth(uint256 tokenAmount) private {
        // generate the uniswap pair path of token -> weth
        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = uniswapV2Router.WETH();

        _approve(address(this), address(uniswapV2Router), tokenAmount);

        // make the swap
        uniswapV2Router.swapExactTokensForETH(
            tokenAmount,
            0, // accept any amount of ETH
            path,
            address(this), // The contract
            block.timestamp
        );
        
        emit SwapTokensForETH(tokenAmount, path);
    }

note:

bool public sellingIsEnabled = true;

but when I make sellingIsEnabled to false , the sell transaction still happens.
how can I prevent token get sold if !sellingIsEnabled ?

No body will help on this subject please?!

Hello, did you check the sellingIsEnabled value again?
do you use trfffle or hardhat?
you can debug and check the sellingIsEnabled value in hardhat console.log in the contract code.

first, please check again.
and then you can switch the sellingIsEnabled value by checking block.timestamp for preventing token to get sold for certian period of time.

Thanks

Hi
thanks for your reply.
The contract must use dex, because of that I'm currently using testnet with remix.
not using neither truffle nor hardhat.

where should I check if you have any advice, please?
Thanks

please contact with me on telegram
@skyhdev

1 Like

if you use hardhat, you can fork mainnet and use dex.

1 Like

awesome!
Can you explain a little more here in public? or have to dm you on tg?

please dm me on tg.

thanks

1 Like

Maybe use ERC20Pauseable?

And use sushiswap for adding liquidity for the test token, it's supporting ropsten and rinkeby testnet network i think.