0

I have a crowdsale contract which creates tokens and assigns them to the crowdsale address. Investors can then send ether to the address and receive tokens from the crowdsale.

In this case how can I set a maximum investment limit? Is it possible to make it so that only a certain number of tokens can be purchased from a particular address?

Similarly, is it possible to implement any form of KYC in a smart contract so that only people that have verified their identity can invest? (If this question should be a separate post, I will edit this post to remove it and resubmit).

Thank you for any help in setting a limit. I appreciate it.

1

I would suggest to have a look at the libraries and contracts of OpenZeppelin and Crowdsale example.

These have been well tested, audited and adhere to security best practices.

Override the validPurchase method in your own Crowdsale contract to implement your custom logic and conditions for participation.

function validPurchase() internal returns (bool) {
    bool lessThanMaxInvestment = msg.value <= 10 ether; // change the value to whatever you need
    bool whitelisted = addressIsWhitelisted(msg.sender); // implement your whitelist function
    return super.validPurchase() && lessThanMaxInvestment && whitelisted;
}

Implementation of a whitelist can be done in several ways. A very simple example could be as follows.

    mapping (address => bool) public whitelist;

    modifier onlyWhitelistAddress() {
        require(whitelist[msg.sender] == true);
        _;
    }

    function addressIsWhitelisted(address _address) public returns (bool) { 
        return whitelist[_address] == true;
    }

    function addWhitelistAddress (address _address) public onlyOwner {
        whitelist[_address] = true;
    }

    function removeWhitelistAddress (address _address) public onlyOwner {
        whitelist[_address] = false;
    }

Or click here for more examples;

0

Have a look at this example crowdsale contract

Override the validPurchase function in your own Crowdsale contract to implement a maximum investment limit.

function validPurchase() internal returns (bool) {
    bool lessThanMaxInvestment = msg.value <= 10 ether; // change the value to whatever you need
    return super.validPurchase() && lessThanMaxInvestment
}
  • This would only implement a maximum limit per transaction, yes? It wouldn't prevent an address from purchasing unlimited tokens via multiple transactions? – John Murphy Feb 16 '18 at 14:20
  • 1
    That't correct. One would have to save the purchasing address in a blacklist in order to prevent future transaktions from that address but then again, an investor trying to buy more could always create multiple wallets and purchase from those – AKroell Feb 17 '18 at 17:00

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.