0

I would like to send a specific amount to another address. That amount is on the account but is freeze/blocked so is not possible to use it until I unblock it based on a contract.

Is it possible to achieve this with solidity?

1

Is it possible to achieve this with solidity?

Yes

You can create a contract like this, the following is just to give an example

pragma solidity 0.4;

contract account {
  address blocker;
  address user;
  bool isBlocked;
  function account(address blockerAccount, address _user) {
    blocker=blockerAccount;
    user=_user;
    isBlocked=true;
  }
  modifier isUnblocked() {
    if(!isBlocked) {
        _;
    }
  }
  modifier isBlocker(address msgSender) {
    if(msgSender == blocker) {
        _;
    }
  }
  modifier isUser(address msgSender) {
    if(msgSender == user) {
        _;
    }
  }
  function unblock() isBlocker(msg.sender) {
    isBlocked=false;
  }
  function withdraw(address withdrawAddress, uint amount) isUser(msg.sender) isUnblocked() {
    withdrawAddress.transfer(amount);
  }
}
  • The problem of this example is that the user can still transfer ethers with another app/contract. Even if my contract says is blocked. – EnZo Jun 5 '17 at 9:10
  • Can I know how because the only way to send money out of the contract is through withdraw function which will not be invoked unlesss the modifier isUnblocked allows it. – joifsi Jun 5 '17 at 9:12
  • Well, this blocking is only valid for this contract. Is a virtual block. The amount can be used in other contracts that I don't have control. – EnZo Jun 5 '17 at 9:18
  • If the money is transferred to this contract along with the initialization of contract, then user will not be able to withdraw, but he can see that the money is intended to the user but he cannot claim it unless unblocked – joifsi Jun 5 '17 at 9:20
  • Did you mean you want to block ether in an Externally Owned Account – joifsi Jun 5 '17 at 9:22
0
pragma solidity 0.4;

contract LockBox {
    uint256 delaySeconds;
    uint256 unlockTime;
    address owner;

    function LockBox(uint256 _delay) {
        delaySeconds = _delay;
        owner = msg.sender;
    }

    // accept a single deposit of a specific amount
    function () payable {
        if (this.balance != 0)
            throw;
        if (msg.value != 10000) // change amount for your use
            throw;
        unlockTime = now + delaySeconds;
    }

    // withdraw if delaySeconds have passed
    function withdraw() {
        if (now <= unlockTime)
            throw;
        if (msg.sender != owner)
            throw;
        owner.transfer(this.balance);
    }
}

Not great code. Should have a lot more protections, but I tried to keep it simple and to the question.

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.