4

For some reason, I'd like to create a kind of token which is limiting the amount someone can send daily (calendar day in a particular country) to others.

The reference time should be the time of the request for the movement.

I guess it may work using now (I'm not 100% sure how, example code is welcome with basic token example https://ethereum.org/token#the-coin ).

The only other option I thought of, would be to provide the time in the transfert call, and eventually to sign it to prevent messing with it : it should then be issued outside of the blockchain, in a central manner, and signed from the contract owner for example ( see How can I sign a piece of data with the private key of an Ethereum address? ), so we can check it in the contract. But I'd really like to avoid this if possible.

3

Yes, you can.

You probably want to use now, as you suggested. What you can do is keep track of the last time anything was spent, and at the beginning of a spent, recalculate the allowance based on ellapsed time.

You'll probably have an easier time with a smooth, constant regrowth of allowance than trying to "reset" it at the end of every day. The EVM has no concept of date. That said, it's possible.

The following snippet is an example of a contract that limits Ether. It is totally untested, but is probably a good start on your way.

contract Limited {
    uint constant public weiPerDay = uint(1 ether);
    uint constant public weiPerSecond = weiPerDay /  uint(1 days);
    address public owner;
    uint public allowance;
    uint public lastSendTime; 

    function Limited() {
        owner = msg.sender;
        lastSendTime = now;
        allowance = weiPerDay;
    }

    function update() {
        allowance += weiPerSecond * (lastSendTime - now);
        if(allowance > weiPerDay) allowance = weiPerDay;
        lastSendTime = now;
    }

    function transfer(address _to, uint _amount) {
        update();
        if((msg.sender != owner) || (_amount > this.balance) ||(_amount > allowance)) throw;
        allowance -= _amount;
        if(!_to.send(_amount)) throw;
    }
}
  • Actually it does not do what I really need, yet it is still interesting. I really need this reset per day in a particular country. I have found this contract that may help: github.com/pipermerriam/ethereum-datetime yet it does not support timezone, nor DST of course. Maybe I can try contributing to it, or fork it to get the date correctly – Florian Traverse Aug 27 '16 at 7:59

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.