Title: Is it possible to code a SC on Bitcoin? Post by: crashedanon on July 02, 2022, 04:54:06 PM Suppose I want my tenant to pay monthly rent using bitcoin and I want the whole process[contract between myself and tenant] to be executed solely on the Bitcoin network. Is there a way to write this smart contract?
If yes then how and where? Title: Re: Is it possible to code a SC on Bitcoin? Post by: jackg on July 02, 2022, 05:36:27 PM Smart contract is quite an abstract name imo.
In countries where it's legal for both to sign a deposit/bond without an intermediary than a 2 of 2 multisig could be produced for this. If you mean to take funds from their wallet and give it to yours, this isn't possible or enforceable but it wouldn't be on any chain without them having to lock up the funds. Title: Re: Is it possible to code a SC on Bitcoin? Post by: NotATether on July 03, 2022, 03:38:32 AM Bitcoin scripts are not Turing complete which means not every use case is possible to code with it. Definitely, it cannot take any real-world or HTTP data as parameters, and its data is limited to numbers on a stack.
Title: Re: Is it possible to code a SC on Bitcoin? Post by: pooya87 on July 03, 2022, 05:11:41 AM Forgetting bitcoin for a moment here, I don't think paying things such as rent automatically is a good idea to begin with. We normally pay the rent manually from our bank account to theirs.
Back to bitcoin again, this could be achieved using locktimes. You basically want a mechanism where the tenant locks some coins up in a smart contract that can only be "unlocked" by the landlord after a certain time. You may also add an extra option for the tenant to be able to spend those coins themselves if they wanted to without the time restriction. So the smart contract could look something like this: Code: OP_IF The limitations of this is that for each month a new address has to be created by only changing the locktime (which changes the hash hence the different address). You also can't set how much the landlord can withdraw since bitcoin scripts can not fetch the amount field of the outputs in the transaction so the tenant has to fund this address with the exact rent value so that the landlord can withdraw all of it. Title: Re: Is it possible to code a SC on Bitcoin? Post by: crashedanon on July 03, 2022, 06:06:22 AM Forgetting bitcoin for a moment here, I don't think paying things such as rent automatically is a good idea to begin with. We normally pay the rent manually from our bank account to theirs. Back to bitcoin again, this could be achieved using locktimes. You basically want a mechanism where the tenant locks some coins up in a smart contract that can only be "unlocked" by the landlord after a certain time. You may also add an extra option for the tenant to be able to spend those coins themselves if they wanted to without the time restriction. So the smart contract could look something like this: Code: OP_IF The limitations of this is that for each month a new address has to be created by only changing the locktime (which changes the hash hence the different address). You also can't set how much the landlord can withdraw since bitcoin scripts can not fetch the amount field of the outputs in the transaction so the tenant has to fund this address with the exact rent value so that the landlord can withdraw all of it. Hey this is exactly what I was looking for, adding more ideas to it, Yet where can I get started? and where should this smart contract be deployed, taking in account that I have some basic knowledge on creating a SC on ethereum and deploying it on the EVM. Title: Re: Is it possible to code a SC on Bitcoin? Post by: pooya87 on July 03, 2022, 06:47:44 AM Hey this is exactly what I was looking for, adding more ideas to it, Yet where can I get started? and where should this smart contract be deployed, taking in account that I have some basic knowledge on creating a SC on ethereum and deploying it on the EVM. I don't know any tool that I can introduce but it is pretty easy to write it yourself if you are familiar with the protocol and since bitcoin scripts are pretty straight forward.All you have to do is to "translate" the code snippet above to a stream of bytes like this (used 2 random keys): Code: OP_IF=0x63 Code: HASH160(redeem)=3AXfCos6dg3NwphudW4iJVewuLBvScrb8t P.S. You may want to test all of this on testnet first. |