1

I'm a newbie in ethereum programming and is playing with an ICO smart contract. I want to know if it is possible to put the below restrictions in the smart contract:

  1. Can I set a maximum amount for ether that can be send to the contract address over a 24-hour period? I want to make sure that a single user doesn't buy all my tokens.

  2. Can I set a maximum amount of ether to be sent to the contract address over a 24-hour period? I want to make sure that only certain amount of my tokens are sold everyday.

2 Answers 2

0

You can not prohibit people from sending Ether to a contract, but you can track the contrcact Ether-/Token -balance and send received Ether back once a cap is reached. You should read a few contracts from open Zepplin, its a great project to get a feeling for writing Smart Contracts. They have ressources in place, for use cases like yours.

To define Time intervals and check against them, there are two ways: I) You can use blocknumbers with "block.number". II) You can use timestamps with "block.timestamp" which returns a unix epoch

see here for details

1
  • This is not correct, actually. You can revert transactions if certain amount of Ether has already been sent to the contract (with receive function, as mentioned in another answer). Similarily, you can connect that logic with a time-based logic Commented Oct 6, 2021 at 17:33
1

You can have a receive function and has a require statement that makes the tx revert if msg.value > someAmount. More info in the solidity docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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