AnswerBun.com

How to limit number of tokens that can be transfered in a given timeframe?

Ethereum Asked by eth.block on November 4, 2020

How can one ensure that an ERC20 token holder can’t send/transfer/other more than X token in given period Y where Y could an hour, day, week, month etc.

Would be better if this can be done without taking up any more storage space.

2 Answers

You could implement coarse control and allow up to X token transfers within period Y. You can have period start on first transfer and expire after Y seconds. This will cost you few storage transfers only, but will release the block later than it should.

To solve the problem if full, you have to store a log (amount + timestamp or block number) of all recent transactions, in an array. On transfer you have to go through that array and check the transfer rate constraint. You have to keep separate array per token holder. This might be expensive and, if sender makes too many transfers, there is a risk of transfer rate check operation exceeding block gas limit. There should be a way to code it in a way to avoid permanent freeze though.

You might find some middle ground, by keeping counts in daily/hourly slots.

You might also investigate this https://github.com/figs999/Ethereum/blob/master/EventStorage.sol.

Answered by abb on November 4, 2020

For contracts, the only source of truth is blockchain, so the answer for the second part is no.

As for the first question: you could save timestamp of last operation for holder Q and before accepting operation require that at least Y time has passed already, e.g:

now >= last_operation + Y

Answered by Grzegorz on November 4, 2020

Add your own answers!

Related Questions

geth: Failed to unlock account

2  Asked on January 16, 2021

   

Mining custom coin

1  Asked on January 4, 2021 by westernwarrior

   

How to validate proper implementation of ERC-1155 contract?

1  Asked on January 3, 2021 by steven-t-cramer

 

truffle-contract cannot deploy in node js

1  Asked on December 30, 2020 by arpit-bharti

 

How to Fix “Stack Too Deep” Error?

4  Asked on December 29, 2020 by jeffrey-liang

 

Can the Geth password be cracked

1  Asked on December 28, 2020

   

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP