Bitcoin Forum
May 02, 2024, 10:31:49 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Is it possible to code a SC on Bitcoin?  (Read 110 times)
crashedanon (OP)
Jr. Member
*
Offline Offline

Activity: 49
Merit: 19


View Profile
July 02, 2022, 04:54:06 PM
Merited by NotATether (2)
 #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?

EE5B04591C6B51C27C4BA1B83393192AEAFC1E46EC0EA88ED766B72C3FBE0263
1714689109
Hero Member
*
Offline Offline

Posts: 1714689109

View Profile Personal Message (Offline)

Ignore
1714689109
Reply with quote  #2

1714689109
Report to moderator
"The nature of Bitcoin is such that once version 0.1 was released, the core design was set in stone for the rest of its lifetime." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714689109
Hero Member
*
Offline Offline

Posts: 1714689109

View Profile Personal Message (Offline)

Ignore
1714689109
Reply with quote  #2

1714689109
Report to moderator
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
July 02, 2022, 05:36:27 PM
Merited by pooya87 (2), ABCbits (1)
 #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.
NotATether
Legendary
*
Offline Offline

Activity: 1596
Merit: 6723


bitcoincleanup.com / bitmixlist.org


View Profile WWW
July 03, 2022, 03:38:32 AM
 #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.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10530



View Profile
July 03, 2022, 05: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
  <time> OP_CheckLocktimeVerify OP_DROP <landlord_pubkey> OP_CheckSig
OP_ELSE
  <tenant_pubkey> OP_CheckSig
OP_ENDIF
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.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
crashedanon (OP)
Jr. Member
*
Offline Offline

Activity: 49
Merit: 19


View Profile
July 03, 2022, 06: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
  <time> OP_CheckLocktimeVerify OP_DROP <landlord_pubkey> OP_CheckSig
OP_ELSE
  <tenant_pubkey> OP_CheckSig
OP_ENDIF
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.

EE5B04591C6B51C27C4BA1B83393192AEAFC1E46EC0EA88ED766B72C3FBE0263
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10530



View Profile
July 03, 2022, 06:47:44 AM
Merited by BlackHatCoiner (4), ABCbits (2)
 #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.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!