Post
Topic
Board Development & Technical Discussion
Merits 25 from 6 users
Re: I want to get started with bitcoin script, what are some good resources?
by
aliashraf
on 03/04/2020, 18:16:47 UTC
⭐ Merited by HCP (10) ,ETFbitcoin (9) ,Coding Enthusiast (2) ,Quickseller (2) ,mocacinno (1) ,o_e_l_e_o (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 end 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 hash. You can use libbitcoin-explorer (bx) for example to this 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.