Author

Topic: Is it possible to code a SC on Bitcoin? (Read 139 times)

legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
July 03, 2022, 06:36:32 AM
#7
Hey this is exactly what I was looking for, adding more ideas to it, Yet where can I get started?

I'd recommend https://min.sc and https://bitcoin.sipa.be/miniscript/ as starter. Those two are high level programming which could be converted to Bitcoin scripting.
legendary
Activity: 3472
Merit: 10611
July 03, 2022, 01:47:44 AM
#6
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
OP_PushData=0x04+0x0023e362 (time=2022-07-29)
OP_CheckLocktimeVerify=0xb1
OP_DROP=0x75
OP_PushData=0x21+0x022f982b2b933fdce5298439dc4e9823a78e081449e60dceb3361db3750f270b19 (pubkey)
....
result=
63040023e362b17521022f982b2b933fdce5298439dc4e9823a78e081449e60dceb3361db3750f270b19ac672102f9168afc6b84e04cf487ef3b66462a1bcdd8908e1c690b8f41cfdbdbceb7f967ac68
Then use that as your redeem script which could be used to produce either a P2SH or a P2WSH address like this:
Code:
HASH160(redeem)=3AXfCos6dg3NwphudW4iJVewuLBvScrb8t
SHA256(redeem)= bc1qcnzcd9q5myq6wzphx0f99lms8sg3ts0peczxn3zw54z2r7xwa8qswuh48l
The rest is just a matter of funding these addresses and later spending from them.
P.S. You may want to test all of this on testnet first.
jr. member
Activity: 49
Merit: 19
July 03, 2022, 01:06:22 AM
#5
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
 
For example the tenant funds this address on 29th but the landlord can only spend it on 1st of next month. If the landlord loses their key the tenant can still spend these coins (it doesn't have the limitations of 2 of 2 multisig).

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.
legendary
Activity: 3472
Merit: 10611
July 03, 2022, 12:11:41 AM
#4
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
 
For example the tenant funds this address on 29th but the landlord can only spend it on 1st of next month. If the landlord loses their key the tenant can still spend these coins (it doesn't have the limitations of 2 of 2 multisig).

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.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
July 02, 2022, 10:38:32 PM
#3
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.
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
July 02, 2022, 12:36:27 PM
#2
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.
jr. member
Activity: 49
Merit: 19
July 02, 2022, 11:54:06 AM
#1
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?
Jump to: