I have 2 persons ( say A or B). They want to have the following agreement. Person ‘A’ specify a deposit (x coins ) for user ‘B’ under a certain condition with a future time lock ‘t’. If user ‘B’ provide a valid solution, he will get the deposit. How can we add a fine payment on user ‘B’ to user ‘A’ if he does not provide a valid solution after the time lock ‘t’ ?? Any detailed smart contract solution will be very helpful??
1 Answer
Yes.
It might help to think of the contract as a vending machine that enforces and process.
User A will deposit some funds. This could be modeled as an offer.
If user A is to possibly receive penalty funds from user B, then user B will also deposit funds. This could be modeled as acceptance of the terms of the offer.
Finally, user B would either complete the task or fail to do so. It's best is the contract can work out for itself that the condition has been met or the time limit has expired so it can determine which user is entitled to funds. Importantly, the contract is limited to doling out funds/assets that are under its contract which is why the first two steps were deposits by both participants.
Hope it helps.
UPDATE
This is a simple deadline example. It does not address all security concerns for a production-ready implementation. For illustrative purposes only. No warranty. ;-)
pragma solidity 0.5.1;
contract Timelock {
uint public deadline;
address owner;
constructor(uint _deadline) public payable {
deadline = _deadline;
owner = msg.sender;
}
function withdrawFunds() public {
require(msg.sender == owner); // funds are only for a certain entity
require(now >= deadline); // cannot be taken before the deadline
msg.sender.transfer(address(this).balance);
}
}
-
Could you please give me an example by a smart contract to clarify the idea ?? Is time lock supported so if user B was honest and provide a valid solution before that time, he can get the deposit? Feb 9, 2019 at 6:55
-
The whole thing is a big ask and not a beginner-level project. A lot depends on the challenge user B is supposed to complete. You seem concerned about the time-lock which is much easier to work out, so I updated the answer with a simple example. Feb 9, 2019 at 16:40