2

I want to do my personal banking in cryptocurrency because I want the customizability, convenience and freedom of money being open source software instead of being heavily limited by the huge variety of inconveniences of physical and digital commercial banks (in my opinion).

I have wanted to be able to create locks on my own money for a long time, nearly 10 years. I just want to be able to force myself to not be able to spend some allotment of money that I put in a sub-account for some specific budgeted future purpose.

I asked ChatGPT and I think I found out that there is already a Solidity function for this called a Time Lock. https://solidity-by-example.org/app/time-lock/

ChatGPT's suggested code was this:

pragma solidity ^0.7.0;

contract TimeLock {
    // The address that can unlock the funds
    address public owner;
    
    // The amount of time (in seconds) that the funds are locked for
    uint256 public lockTime;
    
    // The timestamp when the lock period expires
    uint256 public lockExpiry;
    
    // The amount of funds that are locked
    uint256 public lockedAmount;
    
    // The constructor sets the owner and lock time
    constructor(address _owner, uint256 _lockTime) public {
        owner = _owner;
        lockTime = _lockTime;
        lockExpiry = now + lockTime;
    }
    
    // The lock function can be called by the owner to lock funds
    function lock(uint256 _amount) public {
        require(msg.sender == owner, "Only the owner can lock funds");
        lockedAmount = _amount;
    }
    
    // The unlock function can be called by the owner to unlock the funds
    // after the lock period has expired
    function unlock() public {
        require(msg.sender == owner, "Only the owner can unlock funds");
        require(now >= lockExpiry, "The lock period has not expired");
        msg.sender.transfer(lockedAmount);
    }
}

From what I can see it looks to be pretty good. I think the key part is that "now" is read from the Ethereum block chain and "lockTime" is published to the Ethereum blockchain, so it's not like the owner can circumvent their own block for themselves because it's actually enforced by the decentralised protocol. Right?

(That fascinates me because there is this website where people set goals like to quit smoking and they put money on their goal which will be lost if their audience determines they did not meet their goal - but now with blockchain it appears people can set punishments or incentives for themselves that are enforced without depending on other human beings. Smart contracts appear to have huge repercussions.)

I was also just curious if there are other techniques I should know about to self-restriction in some way. I was also thinking about ways to increase the amount of effort in order to obtain something that is locked. There are various ways but perhaps you could decide you wanted to access funds at any time but in order to do so you had to solve a hard numerical problem that requires your computer to run for some time to solve it. So that would be a "natural" time limit in that you can do it at any time but it's physically impossible to do it faster than the computer can solve the problem.

And any other ideas like that.

Thank you.

2
  • 2
    Are you trying to lock one sum of money per contract? Also, are you trying to deposit money in ETH or some other erc20 token? This contract is not sufficient for either case, btw. I can share some better code if you specify. For example, note that the lock function is not accepting any value. It is just changing the state variable called 'lockedAmount'. Also, unlock has a transfer function, but it isn't defined anywhere. You'd have to give it an erc20 inheritance or define that function. I give chatGPT an F on this assignment... Commented Jan 8, 2023 at 3:28
  • Thanks a bunch. Those specifics - which token - which design; one or many contracts - I am totally flexible on. I’m just interested in the outcome: 1. I check my balance. 2. I specify “600€ is labeled ‘Rent’ and is unspendable until February 1st”. If it is hard to make it impossible to revoke the lock, it is ok if it is inconvenient. Inconvenience still counteracts impulse spending of easy-to-access money. Thanks very much. :) Commented Jan 8, 2023 at 9:37

0

Your Answer

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

Browse other questions tagged or ask your own question.