Post
Topic
Board Development & Technical Discussion
Merits 1 from 1 user
Re: I want to get started with bitcoin script, what are some good resources?
by
BoofBitcoin
on 03/04/2020, 21:28:45 UTC
⭐ Merited by aliashraf (1)
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
      <MyPubkey> CHECKSIGVERIFY
      1
    ENDIF
    <Pubkey1> <Pubkey2> <Pubkey3> 3 CHECKMULTISIG
  ELSE
    <90 days> CHECKSEQUENCEVERIFY DROP
    <MyPubkey> 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.