Lock transfer addresses

Hi,

I’m developing a smart contract and trying to be a bit clever, probably a bit too clever for my own good but wanted to see if anyone has tried to restrict the ability to transfer tokens, specifically I want to be able to only allow transfer of tokens to addresses that are approved.

Obviously, I’ll have a function to be able to add new addresses to the approved list, but I want to know if theres a way that I can restrict the transfer function to only allow transfers TO the approved address list.

Thanks!

Checkout a contract I created for our SEANCE token, found here: SeanceCircle | Address 0x97Ee3C9Cf4E5DE384f95e595a8F327e65265cC4E | SnowTrace

function transfer(address to, uint value) external override obey(sophia) returns (bool)

Note: “sophia” is a role via AccessControl.

You can pretty much do everything in solidity and EVM, except for a few things like:

1 - the contract is not a complete turing machine
2 - a smart contract never has initiative for self-execution
3 - respect the cost/gas limit of the block

In your case, it is easy to solve the problem.

When an account is going to transfer funds you add a require like in this example:

require(addressApproved[to], "errorMessageHere");

You define or remove approved accounts with a function such as:

function setAddressApproved(address account, bool isApproved) public onlyOwner() {
    addressApproved[account] = isApproved;
}

Remember that transferFrom sometimes calls other logic than transfer. Be sure to place this limitation on it as well, as a user may attempt to circumvent this by approving their account for a third party to pull tokens.