Author

Topic: I want to get started with bitcoin script, what are some good resources? (Read 259 times)

newbie
Activity: 12
Merit: 25
OP,
For mastering bitcoin scripting language you need to check resources like this: https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch07.asciidoc

But for creating actual scripts tailored to your needs (like the hypothetical one @ETFbitcoin suggested) without coding it you have two options:

1)lame option: Ignore the mastering phase and just storyboard your requirements right here, waiting for someone to write down a script for you.

2)Try writing down simple scripts tailored to your need and incrementally add more twists to it

In either case, you will come with something like this:
Code:
  IF
    IF
      2
    ELSE
      <60 days> CHECKSEQUENCEVERIFY DROP
       CHECKSIGVERIFY
      1
    ENDIF
     3 CHECKMULTISIG
  ELSE
    <90 days> CHECKSEQUENCEVERIFY DROP
     CHECKSIG
  ENDIF
In this 'simple' script, I send funds to an address which is redeemable with 2 of 3 authorized members of a directing board or something, however, after  60 days if the board doesn't reach required 2 votes, one authorized member can join me to reclaim the funds and after 90 days I can do it by myself.

Now that the script is ready, you need the public keys to put in the placeholders and a map. What map? One that tells you the value of each opcode presented in the script. here you could find one: https://en.bitcoin.it/wiki/Script
After replacing public keys in the script you might decide to calculate its sha256 hash and ripemd160.

You can use libbitcoin-explorer (bx) to get rid of mapping and doing both hashes.  as follows:
Code:
echo {SCRIPT}| bx script-encode | bx sha256 | bx ripemd160
The result would be the hash of your script and it can be used as the destination of a simple P2SH transaction but you and other people who wish to access the funds in the future should have access to the original script. reclaiming complex scripts is another story.



The link you provided has an incredible amount of detail, more than I have seen from other places so far. I did not realize Andreas offered this book for free to read so now I am motivated to give it a read. I have also thought about it and I am pretty sure that I need to learn how to create a raw transaction if I want to create a transaction with a script in it so I think I am slowly getting on the right path. Thanks for the info, its extremely helpful. No worries about me taking the lazy approach, to a fault I am a very DIY type person because I don't trust other people to do it to my standards.
newbie
Activity: 12
Merit: 25
My end goal is I want to learn to create a script that can handle an escrow like service, where 2 parties can agree or disagree that the agreement is to satisfaction and if there is a disagreement then a third party can step in and mediate.
Not wanting to dull your thirst for knowledge... but isn't that sort of escrow scenario already handled by a simple 2-of-3 multisig wallet setup? Huh

I believe so, but I have bigger plans once I figure out some of the basics.
brand new
Activity: 0
Merit: 0
You need to focus on having a good experience and reputation, and, of course, conditions. I found this at Amarkets.
legendary
Activity: 1456
Merit: 1175
Always remember the cause!
OP,
For mastering bitcoin scripting language you need to check resources like this: https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch07.asciidoc

But for creating actual scripts tailored to your needs (like the hypothetical one @ETFbitcoin suggested) without coding it you have two options:

1)lame option: Ignore the mastering phase and just storyboard your requirements right here, waiting for someone to write down a script for you.

2)Try writing down simple scripts tailored to your need and incrementally add more twists to it

In either case, you will come with something like this:
Code:
  IF
    IF
      2
    ELSE
      <60 days> CHECKSEQUENCEVERIFY DROP
       CHECKSIGVERIFY
      1
    ENDIF
     3 CHECKMULTISIG
  ELSE
    <90 days> CHECKSEQUENCEVERIFY DROP
     CHECKSIG
  ENDIF
In this 'simple' script, I send funds to an address which is redeemable with 2 of 3 authorized members of a directing board or something, however, after  60 days if the board doesn't reach required 2 votes, one authorized member can join me to reclaim the funds and after 90 days I can do it by myself.

Now that the script is ready, you need the public keys to put in the placeholders and a map. What map? One that tells you the value of each opcode presented in the script. here you could find one: https://en.bitcoin.it/wiki/Script
After replacing public keys in the script you might decide to calculate its sha256 hash and ripemd160.

You can use libbitcoin-explorer (bx) to get rid of mapping and doing both hashes.  as follows:
Code:
echo {SCRIPT}| bx script-encode | bx sha256 | bx ripemd160
The result would be the hash of your script and it can be used as the destination of a simple P2SH transaction but you and other people who wish to access the funds in the future should have access to the original script. reclaiming complex scripts is another story.


HCP
legendary
Activity: 2086
Merit: 4361
My end goal is I want to learn to create a script that can handle an escrow like service, where 2 parties can agree or disagree that the agreement is to satisfaction and if there is a disagreement then a third party can step in and mediate.
Not wanting to dull your thirst for knowledge... but isn't that sort of escrow scenario already handled by a simple 2-of-3 multisig wallet setup? Huh
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
I'm in the same boat. The basics of bitcoin script language are pretty easy, the problem I've faced is the special cases and undocumented exceptions. Unfortunately the only way to fully understand scripts your only option is to look at the bitcoin core source code (C++ code), start here.

Suppose I create a timelocked script or multisig script, how do I execute that script live or on the testnet?
This answer by me may help you get started on pay to (witness) script hash script types: https://bitcoin.stackexchange.com/a/93733/87716
newbie
Activity: 12
Merit: 25
I have been researching bitcoin script and to my surprise its not as difficult as I first assumed. The problem is every resource I have seen so far from googling around and looking at youtube videos only seem to cover the fundamentals but never really touches on other things like what is the process of serializing and executing my script as a transaction on the blockchain? Most guides cover stuff like what is a stack and how does Alice send bob bitcoin and what that transaction type look like. Suppose I create a timelocked script or multisig script, how do I execute that script live or on the testnet? Also, are there any development "best practices" I should be aware of, or a development environment that can streamline or optimize the process of development, debugging, and deployment?
Jump to: