Coder Social home page Coder Social logo

blockchaincommons / learning-bitcoin-from-the-command-line Goto Github PK

View Code? Open in Web Editor NEW
3.1K 128.0 744.0 9.54 MB

A complete course for learning Bitcoin programming and usage from the command

Python 8.27% Java 6.39% C 35.14% Go 5.51% JavaScript 2.19% Rust 3.80% Shell 2.24% Jupyter Notebook 36.46%
bitcoin cli raw-transactions bitcoin-setup sending-bitcoin-transactions p2sh bitcoin-scripts multisig sending-coins transaction

learning-bitcoin-from-the-command-line's Introduction

Learning Bitcoin from the Command Line 2.2.0

by Christopher Allen and Shannon Appelcline

Learning Bitcoin from the Command Line is a tutorial for working with Bitcoin (and Lightning) that teaches direct interaction with the servers themselves, as the most robust and secure way to begin cryptocurrency work.

NOTE: This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for use.

This tutorial assumes that you have some minimal background of how to use the command line interface. If not, there are many tutorials available, and I have one for Mac users at https://github.com/ChristopherA/intro-mac-command-line.

Translations

If you'd like to make your own translation, please see Contributing, below.

Table of Contents

PART ONE: PREPARING FOR BITCOIN

Status: Finished. Updated for 0.20.

PART TWO: USING BITCOIN-CLI

Status: Finished. Updated for 0.20.

PART THREE: BITCOIN SCRIPTING

Status: Finished. Updated for 0.20 and btcdeb.

PART FOUR: PRIVACY

Status: Finished.

PART FIVE: PROGRAMMING WITH RPC

Status: Finished.

PART SIX: USING LIGHTNING-CLI

Status: Finished.

APPENDICES

Status: Finished.

Status - Beta

v2.1.0 of Learning Bitcoin from the Command Line is feature complete and has undergone full editing and integration. It is ready for learning

We are also tentatively considering what we could include in a v3.0 of the course. If you'd like to support work of that sort, become a GitHub Sponsor or support us at our BTCPay Server, and let us know that Learning Bitcoin was the reason why.

Version History

2.2.0 (November 17, 2021)

2.1.0 (October 12, 2021)

  • New chapter 15 (i2p).
  • Added fixes to wallet usage from 0.21
  • Updated install to new Bitcoin Scripts for 22.0
  • Incorporated numerous fixes revealed by first translation projects

2.0.1 (June 15, 2021)

  • Numerous small patches following 2.0
  • Intended as baseline for translations (2.2.0), but 2.1.0 material on i2p slipped in

2.0.0 (November 3, 2020)

  • Second major release of Learning Bitcoin
  • Added material on Segwit, Tor, hardware wallets, lightning, regtest
  • Completely previous unfinished work on programming using a variety of languages

1.0.0 (pre-2020)

  • Original, extensive but incomplete version
  • Contained comprehensive sections on setup, bitcoin-cli, and scripting

Origin, Authors, Copyright & Licenses

Unless otherwise noted (either in this /README.md or in the file's header comments) the contents of this repository are Copyright © 2020 by Blockchain Commons, LLC, and are licensed under CC-BY.

Financial Support

Learning Bitcoin from the Command Line is a project of Blockchain Commons. We are proudly a "not-for-profit" social benefit corporation committed to open source & open development. Our work is funded entirely by donations and collaborative partnerships with people like you. Every contribution will be spent on building open tools, technologies, and techniques that sustain and advance blockchain and internet security infrastructure and promote an open web.

To financially support further development of Learning Bitcoin from the Command Line and other projects, please consider becoming a Patron of Blockchain Commons through ongoing monthly patronage as a GitHub Sponsor. You can also support Blockchain Commons with bitcoins at our BTCPay Server.

Contributing

We encourage public contributions through issues and pull requests! Please review CONTRIBUTING.md for details on our development process. All contributions to this repository require a GPG signed Contributor License Agreement.

if you would like to provide a translation of Learning Bitcoin into another language, please additionally see TRANSLATING.md.

Discussions

The best place to talk about Blockchain Commons and its projects is in our GitHub Discussions areas.

Blockchain Commons Discussions. For developers, interns, and patrons of Blockchain Commons, please use the discussions area of the Community repo to talk about general Blockchain Commons issues, the intern program, or topics other than those covered by the Gordian Developer Community or the Gordian User Community.'

Other Questions & Problems

As an open-source, open-development community, Blockchain Commons does not have the resources to provide direct support of our projects. Please consider the discussions area as a locale where you might get answers to questions. Alternatively, please use this repository's issues feature. Unfortunately, we can not make any promises on response time.

If your company requires support to use our projects, please feel free to contact us directly about options. We may be able to offer you a contract for support from one of our contributors, or we might be able to point you to another entity who can offer the contractual support that you need.

Credits

The following people directly contributed to this repository. You can add your name here by getting involved. The first step is learning how to contribute from our CONTRIBUTING.md documentation.

Name Role Github Email GPG Fingerprint
Christopher Allen Lead Author @ChristopherA <[email protected]> FDFE 14A5 4ECB 30FC 5D22 74EF F8D3 6C91 3574 05ED
Shannon Appelcline Lead Author @shannona <[email protected]> 7EC6 B928 606F 27AD

Additional contributions are listed below:

Role Names
Contributors: gg2001 (Go, Node.js sections), gorazdko (Rust section), Javier Vargas (C, Java, Lightning, Tor sections), jodobear (Appendix: Compiling Bitcoin, Python section), Prayank (i2p sections)
Reviewers: Glen Willem @gwillem
Sponsors: Blockstream Corporation

Translation Credits

Thanks to the volunteers who spent extensive time writing and reviewing other-language translations of the original English-language course.

Portuguese Translation

Name Role Github
Namcios Translator & Reviewer @namcios
Korea Translator & Reviewer @KoreaComK
Luke Pavsky Translator & Reviewer @lukedevj
hgrams Translator & Reviewer @hgrams

Spanish Translation

Name Role GitHub
Ian Culp Translator & Reviewer @icculp
Maxi Goyheneche Translator @maxcrowar
Said Rahal Translator @srahalh
César A. Vallero Translator & Reviewer @csralvall
Javier Vargas Translator & Reviewer @javiervargas

Responsible Disclosure

We want to keep all of our software safe for everyone. If you have discovered a security vulnerability, we appreciate your help in disclosing it to us in a responsible manner. We are unfortunately not able to offer bug bounties at this time.

We do ask that you offer us good faith and use best efforts not to leak information or harm any user, their data, or our developer community. Please give us a reasonable amount of time to fix the issue before you publish it. Do not defraud our users or us in the process of discovery. We promise not to bring legal action against researchers who point out a problem provided they do their best to follow the these guidelines.

Reporting a Vulnerability

Please report suspected security vulnerabilities in private via email to [email protected] (do not use this email for support). Please do NOT create publicly viewable issues for suspected security vulnerabilities.

The following keys may be used to communicate sensitive information to developers:

Name Fingerprint
Christopher Allen FDFE 14A5 4ECB 30FC 5D22 74EF F8D3 6C91 3574 05ED

You can import a key by running the following command with that individual’s fingerprint: gpg --recv-keys "<fingerprint>" Ensure that you put quotes around fingerprints that contain spaces.

learning-bitcoin-from-the-command-line's People

Contributors

bvolpato avatar christophera avatar csralvall avatar danpape avatar dimitris-t avatar felipegontijo avatar gg2001 avatar goosie avatar hgrams avatar icculp avatar jakobalexander avatar javiervargas avatar jbaczuk avatar jkandzi avatar jodobear avatar joegesualdo avatar kallewoof avatar keblek avatar koreacomk avatar lukedevj avatar maxcrowar avatar mkcisse avatar namcios avatar officer47p avatar shannona avatar srahalh avatar tcharding avatar wintercooled avatar yojoots avatar zerotobtc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learning-bitcoin-from-the-command-line's Issues

Section 2.1 doesnt work on Debian 10?

Hi I tried to follow the setting up guide but I was not able to get it to work on Debian 10 on digital ocean.

I was however able to successfully follow this https://www.digitalocean.com/community/tutorials/initial-server-setup-with-debian-10

this
https://medium.com/@meeDamian/bitcoin-full-node-on-rbp3-revised-88bb7c8ef1d1

and I also found this
https://github.com/jtesta/ssh-audit

Maybe its time to update the guide?

What is currently in Section 2.1 is really complicated IMO.

Accessing bitcoin with python

when will this part get completed? approximate date? and right now I wanted some way to connect with the bitcoin using python. Do u have something in mind I can start from?

CSV - Small typo in printf command

Hello,

I noticed a small typo in a shell command, in 9.3: Using CSV in Scripts, paragraph create-a-csv-relative-time.

Actual

Finally, bitwise-or the 23rd bit into the hex value you created:

$ relativevalue=$(printf '%x\n' $((0x$hexvalue | 0x400000)))
$ echo $relativevalue
4224679

Expected

Finally, bitwise-or the 23rd bit into the hex value you created:

$ relativevalue=$(printf '%d\n' $((0x$hexvalue | 0x400000)))
$ echo $relativevalue
4224679

It should be %d\n to get a decimal value.

SignRawTransaction example no longer works

URL: https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/04_2_Creating_a_Raw_Transaction.md#sign-the-raw-transaction

I don't think[1] this works with Bitcoin Core 0.16.0 and above because its wallet defaults to using P2SH-wrapped segwit and segwit requires passing the value of each input being signed to signrawtransaction. For more information, please see this related issue: bitcoin-dot-org/Bitcoin.org#2538

[1] I don't see where in the tutorial it explains to the user how to get an address, so I'm assuming they're just getting whatever address the wallet returns by default, which would be P2SH-wrapped segwit in 0.16.0 and above. If the docs don't already explain how to get an address and I just missed it, I'd suggest that you make that explicit.

Sending Coins the Easy Way: Transaction never broadcasts

I am following along on section 4.1 and when I try to do:

bitcoin-cli sendtoaddress [address] [amount]

Everything seems to work fine but my transaction stays with 0 confirmations (over 24 hours now). When I check the transaction the way the tutorial suggests everything looks the same.

{
  "amount": -0.10000000,
  "fee": -0.00022400,
  "confirmations": 0,
  "trusted": false,
  "txid": "888e82fc464e6f520ffd016aadbc1aeeb52c69ca51faf57f3573ec5c90be1a9c",
  "walletconflicts": [
    "e8a1ea84e968bc1e4cd04e9f762e5145e3c620bd70d250ce422df71d32c00d48",
    "aad4eb89a13fd92268363e18f4e92cd890622e58494ff1179df579a4edff6bef"
  ],
  "time": 1511656829,
  "timereceived": 1511656829,
  "bip125-replaceable": "unknown",
  "details": [
    {
      "account": "",
      "address": "2N8hwP1WmJrFF5QWABn38y63uYLhnJYJYTF",
      "category": "send",
      "amount": -0.10000000,
      "vout": 0,
      "fee": -0.00022400,
      "abandoned": false
    }
  ],
  "hex": "020000000151dd79ce6ffc47739b17e5f984942eab0e48d6243a09ca4136bf8730c0d5b099000000006a4730440220212b8fbfdd7119dbb7473dad2493b4e40c7a82dc1b463075030242a8d97556770220300fc6be4d446fef32a448a2e372982933bdc3a8a6f00119c5b0869b5bcefe430121026910802d0ac183a6195f5bac6dd9e9d613dbe2fe96275cfbe2884bdc4a1a8a53feffffff02809698000000000017a914a9974100aeee974a20cda9a2f545704a0ab54fdc8780b62607000000001976a9142c674fa2afe460ad7eaf0d9dd97c85461966fd7688ac2df11200"
}

I also expected to see my transaction in the mempool of my node but that just returns an empty array. When I pass true to bitcoin-cli getrawmempool true I get an empty json object.

I am wondering if there is something that would prevent my node from broadcasting transactions? Or if my mempool is somehow set up wrong?

Great tutorial, it's thought me a lot so far. I will just move to the next sections and hopefully figure this out later. Cheers.

importaddress vs importpubkey

In this section we use importaddress to load our multisignature address into the bitcoin wallet. I looked at the docs for inputaddress and it said this:

If you have the full public key, you should call importpubkey instead of this

Are we able to get the multisig pubkey and use importpubkey?

How to sign a raw transaction? bitcoin core version v 0.17.0

Hey! I have read this tutorial: https://support.bitpay.com/hc/en-us/articles/115002990903-How-can-I-recover-funds-from-a-Bitcoin-Core-wallet-dat-file-without-having-the-entire-blockchain-downloaded-

I am trying to recover some funds transfered to my bitcoin core wallet without having to wait several days. There are many blockchains to be downloaded (only 4% in 3 days)

What to do? I can't sign the raw transaction. The system gives the following message:

signrawtransaction is deprecated and will be fully removed in v0.18. To use signrawtransaction in v0.17, restart bitcoind with -deprecatedrpc=signrawtransaction.
Projects should transition to using signrawtransactionwithkey and signrawtransactionwithwallet before upgrading to v0.18 (code -32)

I could, however, create the raw transaction.

I just need to sign the transaction and send it.

I already tried to import the private key in a blockchain account, but the balance is still "not spendable"

btcinfo has an outdated command (bitcoin-cli getinfo) for 0.16.0

~# btcinfo
"balance": 0.00000000,
error code: -32601
error message:
getinfo

This call was removed in version 0.16.0. Use the appropriate fields from:

  • getblockchaininfo: blocks, difficulty, chain
  • getnetworkinfo: version, protocolversion, timeoffset, connections, proxy, relayfee, warnings
  • getwalletinfo: balance, keypoololdest, keypoolsize, paytxfee, unlocked_until, walletversion

bitcoin-cli has the option -getinfo to collect and format these in the old format.

Confusing turn

In Understanding the Bitcoin Transaction https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/04_2_Creating_a_Raw_Transaction.md#understand-the-bitcoin-transaction
there is a sentence that doesn't quite make sense.

For now, we won't worry about that, but the creation of a change address will be what turns the theory of this section until the actual use of the next subsection.

Not sure what it means to "turns the theory of this section until the actual use".

Incorrect value of nSequence in relative timelock

Hi there,

In part Understand How CSV Really Works of passage 9.3: Using CSV in Scripts

CSV has many of the same subtleties in usage as CLTV:

  • The nVersion field must be set to 2 or more.
  • The nSequence field must be set to less than 0xf0000000.
  • When CSV is run, there must be an operand on the stack that's between 0 and 0xf0000000-1.
  • Both the stack operand and nSequence must have the same value on the 23rd bit.
  • The nSequence must be greater than or equal to the stack operand.

Value 0xf0000000 in the 2nd and 3rd tip, I think it should be 0x80000000

For my understanding

  • nSequence = 0xffffffff, no timelock
  • 0x80000000 <= nSequence < 0xffffffff, indicates absolute timelock, nLocktime or CLTV, usually set to 0xfffffffe
  • nSequence < 0x800000000, indicates relative timelock, nSequence or CSV

Please help confirm this or correct me if I got wrong. Thanks 😄

Section 2:1 Setup Variables - Incorrect Variable BITCOIN

The following command export BITCOIN=bitcoin-core-0.16.2 causes

$ wget https://bitcoin.org/bin/$BITCOIN/$BITCOINPLAIN-x86_64-linux-gnu.tar.gz -O ~user1/$BITCOINPLAIN-x86_64-linux-gnu.tar.gz

$ wget https://bitcoin.org/bin/$BITCOIN/SHA256SUMS.asc -O ~user1/SHA256SUMS.asc to fail.

The solution is to navigate to https://bitcoin.org/bin/ and find a bitcoin version that exists and rerun the export variable command.

EG: export BITCOIN= bitcoin-core-0.16.3

Alias btcinfo gives error on bitcoind 0.16.2

Using Bitcoin Core 0.16.2. In the file here, your btcinfo alias no longer works. I get:

This call was removed in version 0.16.0. Use the appropriate fields from:
- getblockchaininfo: blocks, difficulty, chain
- getnetworkinfo: version, protocolversion, timeoffset, connections, proxy, relayfee, warnings
- getwalletinfo: balance, keypoololdest, keypoolsize, paytxfee, unlocked_until, walletversion

Section 9.3: nSequence clarification & Scripting tool

  1. In section 9.3, you write that
    " with a nVersion value of 2, a nSequence value of 0x00000001 to 0xf0000000-1 allows relative timelock, RBF, and nTimeLock"

However, if the 32nd bit needs to be 0 for relative timelock, would that not imply that we cannot have 0xf as as the first hexadecimal character?

0x f000 0000 - 1 = 0x efff ffff. This translates to (1110) for the first hex character f, which would flag the 32nd bit.

0111 1111 .... 5 times (1111).... 1111 = 7fff ffff

Instead, the hexadecimal notation should be 0x00000001 to 0x7fffffff?
If I am wrong, help me understand what am I missing out here?

  1. Haven't used this yet but might be helpful to take a look at this as you write the chapter on P2SH out - https://docs.ivy-lang.org/bitcoin/
    Thanks for your help!

Scripting a Multisig

Hi,
I read this https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/08_4_Scripting_a_Multisig.md.It is good.
I am working on creating simple p2sh script. But first round of validation can be done easily. Can you please tell about how to do the second round of validation that is deserializing the redeemscript and combine with the operands and do the operation?
Because when we give a scriptsig for a locking script, some of the values will be pushed on to stack initially follwed by whole redeemscript pushed as element into the stack. In that case, how will you deserialize and verify the internal script?

Understand If/Then Ordering - should be 'unlocking script'

Hello!
There is an error in Understand If/Then Ordering

Actual

The owner of <privKeyA> would put <signatureA> <pubKeyA> True in his locking script, while the owner of <privKeyB> would put <signatureB> <pubKeyB> False in her locking script. 

Expected

The owner of <privKeyA> would put <signatureA> <pubKeyA> True in his unlocking script, while the owner of <privKeyB> would put <signatureB> <pubKeyB> False in her unlocking script. 

signrawtransaction should be replaced by signrawtransactionwithwallet

The signrawtransaction command no longer works using default setting in the latest bitcoin core version v0.17.

signrawtransaction is deprecated and will be fully removed in v0.18. To use signrawtransaction in v0.17, restart bitcoind with -deprecatedrpc=signrawtransaction.
Projects should transition to using signrawtransactionwithkey and signrawtransactionwithwallet before upgrading to v0.18

These sections should be converted to use signrawtransactionwithwallet

4.2 Creating a Raw Transaction
4.3 Creating a Raw Transaction with Named Arguments
4.5: Sending Coins with Automated Raw Transactions

6_1 Signing multisig transaction CLI command

The following command (chapter 6_1_Sending_a_Transaction_to_a_Multisig) can not be executed because env variable $address1 is an address and not a pub key:

machine1$ bitcoin-cli -named createmultisig nrequired=2 keys='''["'$address1'","0367c4f666f18279009c941e57fab3e42653c6553e5ca092c104d1db279e328a28"]'''

Therefore $address1 should be changed to the pubkey of address1 (same as with address2).

Chinese Translation?

Hi, I am offering to contribute a Chinese translation. Anyway to get started?

Alias btcblock does not produce a block number from the wget command.

Hello,

The second half of the btcblock alias does not seem to be working for me:

alias btcblock="echo \`bitcoin-cli getblockcount 2>&1\`/\`wget - http://blockexplorer.com/testnet/q/getblockcount 2> /dev/null | cut -d : -f2 | rev | cut -c 2- | rev\`"

The getblockcount seems to work but the results I receive when I run the alias is "x/ " where x is the number of blocks on the longest chain. There is not input after "/".

Please advise.

difficult to follow p2pkh running a real example

https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/07_3_Scripting_a_P2PKH.md#running-through-a-real-example

I tried my own transaction using the testnet. i first looked at my first unspent output and used that to send a new transaction to the testnet.

  "txid": "8442b25c5bef594d55adf80e23e5fa320af000c67269837b641a0621863ab428",
  "hash": "8442b25c5bef594d55adf80e23e5fa320af000c67269837b641a0621863ab428",
  "version": 2,
  "size": 224,
  "vsize": 224,
  "locktime": 0,
  "vin": [
    {
      "txid": "2f3359c635079cf03e07ee477d967df40bf2a7f49a9d85259d0b5f7013493190",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100e3262f186304c78fbf62cc34a94a8ddf8dbc3b0844c393ed7f95da2723b74313022073c0a33890737417b71c4db905fd83f17c137c0548b6b5003a0d6fa0a94a4e20[ALL] 03dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d22",
        "hex": "483045022100e3262f186304c78fbf62cc34a94a8ddf8dbc3b0844c393ed7f95da2723b74313022073c0a33890737417b71c4db905fd83f17c137c0548b6b5003a0d6fa0a94a4e20012103dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d22"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.19750000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 a9974100aeee974a20cda9a2f545704a0ab54fdc OP_EQUAL",
        "hex": "a914a9974100aeee974a20cda9a2f545704a0ab54fdc87",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2N8hwP1WmJrFF5QWABn38y63uYLhnJYJYTF"
        ]
      }
    }, 
    {
      "value": 0.19550000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 9dae41748a7596237428b9541d593429e4ef26b1 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9149dae41748a7596237428b9541d593429e4ef26b188ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "muth8fjUhvXAu1QZdmygf5wzVBXeUviPcD"
        ]
      }
    }
  ]
}

i waited for this to get confirmed to recieve a new value of 0.1955 to my wallet. This 0.19555 became a new unspent utxo. i then used this transaction to send to the testnet again

{
  "txid": "1a3851e8cc9ee0c959de0494aa8293e206f716a98fb7d9b5d6da6652160ddb9e",
  "hash": "1a3851e8cc9ee0c959de0494aa8293e206f716a98fb7d9b5d6da6652160ddb9e",
  "version": 2,
  "size": 223,
  "vsize": 223,
  "locktime": 0,
  "vin": [
    {
      "txid": "8442b25c5bef594d55adf80e23e5fa320af000c67269837b641a0621863ab428",
      "vout": 1,
      "scriptSig": {
        "asm": "3044022017b3b13af64945fa14eacea7c20602a8b585294659d353f90e47b080272c1bd0022021e4cc87e5d480c256f269ff95d955a30b2039820f2466b166719879421be6a3[ALL] 02ad4fc1f35861f4853fbeceda57da004cadee4a5b4f4367deb52c2c133b2df40d",
        "hex": "473044022017b3b13af64945fa14eacea7c20602a8b585294659d353f90e47b080272c1bd0022021e4cc87e5d480c256f269ff95d955a30b2039820f2466b166719879421be6a3012102ad4fc1f35861f4853fbeceda57da004cadee4a5b4f4367deb52c2c133b2df40d"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.09775000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 a9974100aeee974a20cda9a2f545704a0ab54fdc OP_EQUAL",
        "hex": "a914a9974100aeee974a20cda9a2f545704a0ab54fdc87",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2N8hwP1WmJrFF5QWABn38y63uYLhnJYJYTF"
        ]
      }
    }, 
    {
      "value": 0.09575000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 f1510b435c94daff54e9018f6c1836c9a2a80291 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914f1510b435c94daff54e9018f6c1836c9a2a8029188ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "n3WvEKZGqCozMVyUgWid2xHn25yWyEuiSE"
        ]
      }
    }
  ]
}

i then run the script debugger. I think I'm confused which transaction to append to one another.

btcdeb 483045022100e3262f186304c78fbf62cc34a94a8ddf8dbc3b0844c393ed7f95da2723b74313022073c0a33890737417b71c4db905fd83f17c137c0548b6b5003a0d6fa0a94a4e20012103dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d2276a9149dae41748a7596237428b9541d593429e4ef26b188ac
btcdeb -- type `btcdeb -h` for start up options
valid script
7 op script loaded. type `help` for usage information
script                                                             |  stack 
-------------------------------------------------------------------+--------
3045022100e3262f186304c78fbf62cc34a94a8ddf8dbc3b0844c393ed7f95d... | 
03dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d22 | 
OP_DUP                                                             | 
OP_HASH160                                                         | 
9dae41748a7596237428b9541d593429e4ef26b1                           | 
OP_EQUALVERIFY                                                     | 
OP_CHECKSIG                                                        | 
#0001 3045022100e3262f186304c78fbf62cc34a94a8ddf8dbc3b0844c393ed7f95da2723b74313022073c0a33890737417b71c4db905fd83f17c137c0548b6b5003a0d6fa0a94a4e2001
btcdeb> step
		<> PUSH stack 3045022100e3262f186304c78fbf62cc34a94a8ddf8dbc3b0844c393ed7f95da2723b74313022073c0a33890737417b71c4db905fd83f17c137c0548b6b5003a0d6fa0a94a4e2001
script                                                             |                                                             stack 
-------------------------------------------------------------------+-------------------------------------------------------------------
03dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d22 | 3045022100e3262f186304c78fbf62cc34a94a8ddf8dbc3b0844c393ed7f95d...
OP_DUP                                                             | 
OP_HASH160                                                         | 
9dae41748a7596237428b9541d593429e4ef26b1                           | 
OP_EQUALVERIFY                                                     | 
OP_CHECKSIG                                                        | 
#0002 03dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d22
btcdeb> step
		<> PUSH stack 03dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d22
script                                                             |                                                             stack 
-------------------------------------------------------------------+-------------------------------------------------------------------
OP_DUP                                                             | 03dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d22
OP_HASH160                                                         | 3045022100e3262f186304c78fbf62cc34a94a8ddf8dbc3b0844c393ed7f95d...
9dae41748a7596237428b9541d593429e4ef26b1                           | 
OP_EQUALVERIFY                                                     | 
OP_CHECKSIG                                                        | 
#0003 OP_DUP
btcdeb> step
		<> PUSH stack 03dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d22
script                                                             |                                                             stack 
-------------------------------------------------------------------+-------------------------------------------------------------------
OP_HASH160                                                         | 03dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d22
9dae41748a7596237428b9541d593429e4ef26b1                           | 03dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d22
OP_EQUALVERIFY                                                     | 3045022100e3262f186304c78fbf62cc34a94a8ddf8dbc3b0844c393ed7f95d...
OP_CHECKSIG                                                        | 
#0004 OP_HASH160
btcdeb> step
		<> POP  stack
		<> PUSH stack 79c4a0649c807b4393ea3fe8c1c69f9b58c69457
script                                                             |                                                             stack 
-------------------------------------------------------------------+-------------------------------------------------------------------
9dae41748a7596237428b9541d593429e4ef26b1                           |                           79c4a0649c807b4393ea3fe8c1c69f9b58c69457
OP_EQUALVERIFY                                                     | 03dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d22
OP_CHECKSIG                                                        | 3045022100e3262f186304c78fbf62cc34a94a8ddf8dbc3b0844c393ed7f95d...
#0005 9dae41748a7596237428b9541d593429e4ef26b1
btcdeb> step
		<> PUSH stack 9dae41748a7596237428b9541d593429e4ef26b1
script                                                             |                                                             stack 
-------------------------------------------------------------------+-------------------------------------------------------------------
OP_EQUALVERIFY                                                     |                           9dae41748a7596237428b9541d593429e4ef26b1
OP_CHECKSIG                                                        |                           79c4a0649c807b4393ea3fe8c1c69f9b58c69457
                                                                   | 03dd0441340a9dcf400210fd72065e6582f08fae540a39132f122b097c621e7d22
                                                                   | 3045022100e3262f186304c78fbf62cc34a94a8ddf8dbc3b0844c393ed7f95d...
#0006 OP_EQUALVERIFY
btcdeb> step
		<> POP  stack
		<> POP  stack
		<> PUSH stack 
error: Script failed an OP_EQUALVERIFY operation

btcdeb script argument notation throws ambiguous input 515293 is interpreted as a numeric value

This does not currently work:

$ btcdeb $(btcc OP_1 OP_2 OP_ADD)

because $ btcc OP_1 OP_2 OP_ADD returns 515293

$ btcdeb 515293
btcdeb -- type `btcdeb -h` for start up options
warning: ambiguous input 515293 is interpreted as a numeric value; use 0x515293 to force into hexadecimal interpretation
invalid script

Which can be fixed using $ btcdeb 0x515293

But, suggest using this notation as shown in btcdeb docs

$ btcdeb '[OP_1 OP_2 OP_ADD]'

Blockchains probably will not be helpful if Transactors should be secret?

Blockchains probably will not be helpful if:

Users are trusted:
e.g.: transactions occur within a business or organization.
e.g.: transactions are overseen by a central authority.
Secrecy is required:
e.g.: Information should be secret.
e.g.: **Transactions should be secret.**
e.g.: *Transactors should be secret.**
Users **need instant transaction finality, in less than an hour.**

so you are saying blockchains like zcash or cryptonote shouldn't use a blockchain?

Also isn't litecoin and ethereum blocks are faster than (6 blocks * 10mins)

or is this just opinion? (sincere question by a noob)

error: couldn't connect to server: unknown (code -1)

Hi Christopher,

I have just started to follow your tutorial for an intro to Bitcoin and I think it's awesome.

Right now, my Bitcoin daemon is downloading the blocks (testnet). However, I notice that after downloading about 600,000 out of 1,355,036 blocks, the server got disconnected. Only upon running the command btcblock do I get the following message:

error: couldn't connect to server: unknown (code -1) (make sure server is running and you are connecting to the correct RPC port)/1355033

I have tried restarting the daemon and the download, and even rebooted my VPS, but I will always get to the same error. Any tips on this?

Fungible?

In 03_4_Receiving_a_Transaction.md, it states

Though the addresses are fairly private, transactions can be examined as they go in and out of addresses. This makes the funds ultimately fungible and makes the privacy vulnerable to statistical analysis.

Is it really the visibility of transactions that makes the funds fungible?

Curl parse error

I am using your tutorial to try and create a raw transaction and am following everything to the T. I am using swift and am able to list unspent outputs and get a change a address with no issues. However I get the parse error when creating the raw transaction, I have tried many different syntaxes but always get an error, I have triple checked the addresses and amounts corresponding to the UTXO. Any advice would be greatly appreciated, here is the code that is giving me the error:

{"jsonrpc":"1.0","id":"curltest","method":"createrawtransaction","params":[''[{"txid":"515fa300542890ce3f63fa092ce0ba871c5897a123831b1557555878dde639d4","vout":0}]'', ''{"mm8xEm6YS8B7ErLYYqcdF6URWkS1BWnqtY":0.0001, "2N7rCmXqXiBPbHKRv1H31gAGf4QKZB1UVNb":0.79988325}'']}

and here is the error:

error = { code = "-32700"; message = "Parse error"; }

Signature Check Broken in Setup

gpg: directory '/home/user1/.gnupg' created
gpg: keybox '/home/user1/.gnupg/pubring.kbx' created
gpg: cannot open '/dev/tty': No such device or address
SHASIG is 
VERIFICATION ERROR: Signature for Bitcoin did not verify!
VERIFICATION SUCCESS / SHA: 9d6b472dc2aceedb1a974b93a3003a81b7e0265963bd2aa0acdcb17598215a4f

Address does not refer to key

Hello, I have been going through the steps, and tried signing a message per the steps, and I get the Address does not refer to key errorl

Hello, I am new here.

I am experimenting with a full node, and setup a new node on ubuntu - Core 0.16.0.
I'm running my bitcoind in test-net

I'm running a test-net bitcoin daemon.

Whenever I try to sign a message with my pub key, it shows this error

Steps:

  1. bitcoin-cli getnewaddress
    --> It produced an address: 2N2yv1XcYfNXR54J7ZJvBxY6ZnmZFbz89tm

  2. bitcoin-cli signmessage "2N2yv1XcYfNXR54J7ZJvBxY6ZnmZFbz89tm" "Hello there"

--> Get following error
error code: -3
error message:
Address does not refer to key

This is pretty vanilla functionality - why is this happening and how to address?

Thank you in advance

VPS Stackscript setup

I am trying to setup the a VPS using linode but when I try to save the script I get an 'Internal Server' error at the top? Any ideas?

Screen Shot 2020-03-24 at 4 05 55 PM

What's the meaning of triple single quotes

In the chapter:

4.5: Sending Coins with Automated Raw Transactions

$ unfinishedtx=$(bitcoin-cli -named createrawtransaction inputs='''[]''' outputs='''{ "'$recipient'": 1.0 }''')

What's the meaning of triple single quotes like '''[]''' ?

Chap 3 export BITCOIN and BITCOINPLAIN, vars not persistenting on ssh logout

Thanks for this wonderful repo. Such an exciting place to learn about bitcoin in a linear fashion.

I have been following Chap 3 meticulously via the Linode VPS but have noticed that the setup variables instructions use export which to me preserves both variables only across sub-shells. If I logout, log back in and try echo $BITCOIN , it returns blank. The crontab entry to start the bitcoin daemon whenever the VPS restarts also won't work unless I go through the setup variables instructions again. Am I missing something?

Chapter 06_01: pubkey information

The old command for getting the public key of an address is described in Chapter 06_01:
machine2$ bitcoin-cli -named validateaddress address=$address2

The new command since 0.17.0 would be:
machine2$ bitcoin-cli -named getaddressinfo address=$address2

Renaming pages with leading zeros

We should probably rename those pages without a leading zero with a zero, so that they sort properly in the github view and via ls.

How to calculate locking script in 2-3 multisig/P2SH

Environment

  • Version: Bitcoin Core Daemon version v0.16.99.0-7c32b41
  • OS: Ubuntu 14.04.5 LTS x64
  • Network: Bitcoin Testnet

What I want to do

I want to generate a 2-3 multisig address, and pay to it.

What I've known about P2SH

locking script: RIPEMD160<Hash256<2 PK1 PK2 PK3 3 OP_CHECKMULTISIG>>

What I've done

  1. generate 3 new address, dump private key
root@ubuntu:~# bitcoin-cli -testnet getnewaddress
2Mv3bjnJv2XtDjAvjYfKjwXBHCmojCiu3mz
root@ubuntu:~# bitcoin-cli -testnet dumpprivkey 2Mv3bjnJv2XtDjAvjYfKjwXBHCmojCiu3mz
cPegPf2xaeaqYB9kqqM2gzVPPXnAmwCME2KjsAQG6gkVnbxZpTKo
root@ubuntu:~# bitcoin-cli -testnet getnewaddress
2MsJ1eKdVZrYLptCLGNrvuTvVjVQzR2FR5o
root@ubuntu:~# bitcoin-cli -testnet dumpprivkey 2MsJ1eKdVZrYLptCLGNrvuTvVjVQzR2FR5o
cQ8ZUeBy27NKafYioHp4f3isHFTFuAx65vPf6dgUgxdNSBegsW3W
root@ubuntu:~# bitcoin-cli -testnet getnewaddress
2N4fwyEsVN9Lowja9ab5ek4R3yck3PmasdN
root@ubuntu:~# bitcoin-cli -testnet dumpprivkey 2N4fwyEsVN9Lowja9ab5ek4R3yck3PmasdN
cVTFSWeeeB9uoKZgcCbCN7eovztbQzNySGsruAFrVSiiX8ogMqtJ
  1. generate 2-3 multisig address
root@ubuntu:~# bitcoin-cli -testnet addmultisigaddress 2 "[\"2Mv3bjnJv2XtDjAvjYfKjwXBHCmojCiu3mz\",\"2MsJ1eKdVZrYLptCLGNrvuTvVjVQzR2FR5o\", \"2N4fwyEsVN9Lowja9ab5ek4R3yck3PmasdN\"]" "test account"
{
    "address": "2MwgnLokB4WA9NLNd6yL36AvPHHVChDh5r3",
    "redeemScript": "522102f396b11941706b0424499fbf679c3e5987a8d2bf5b47116ec60ceb4f71804d46210256c0ec8ee73ba5fff9b12910880c12be9ff7d15f1f1b5d64685c3bcbdeb6734d210269321ca40da82f1fb8da8932b25beb96b4a84e6af593e89ee64e4c3f867eb7b553ae"
}

If call validateaddress, get this:

root@ubuntu:~# bitcoin-cli -testnet validateaddress 2MwgnLokB4WA9NLNd6yL36AvPHHVChDh5r3
{
    "isvalid": true,
    "address": "2MwgnLokB4WA9NLNd6yL36AvPHHVChDh5r3",
    "scriptPubKey": "a91430b5e8e9151e46be789562580b0118911d875f3d87",
    "isscript": true,
    "iswitness": false
}
  1. call sendtoaddress to send 0.527 BTC to 2MwgnLokB4WA9NLNd6yL36AvPHHVChDh5r3
root@ubuntu:~# bitcoin-cli -testnet sendtoaddress 2MwgnLokB4WA9NLNd6yL36AvPHHVChDh5r3 0.527
5332ed1482e665c6f7146283991ad69c05af99cfebab344729d54b382f68a46c

bash_profile not working for ubuntu

Hello,
I am aware you are using debian, but I think many people will follow this on their standard linux distro. Ubuntu (16.04) is not reading from bash_profile properly but instead from bashrc (at least in the desktop enviroment, might work at a login shell), so writing the aliases won't work in ubuntu (used here: https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/02_1_Setting_Up_a_Bitcoin-Core_VPS_by_Hand.md and https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/03_1_Verifying_Your_Bitcoin_Setup.md)
You might consider adding something like ('use ~/.bashrc instead of ~/.bash_profile on ubuntu')

Broken link in 06.5 Sending a Transaction with Data

Clicking the link in the sentence

Again, remember that you can look at this transaction using a blockchainexplorer:
https://live.blockcypher.com/btc-testnet/tx/3a62b396afb8d8a59ebe7b9e52d6aa2485f1082a1d3fc6ece61fb8b55373823d/

gives a page with the error message.

No transaction found with the hash 3a62b396afb8d8a59ebe7b9e52d6aa2485f1082a1d3fc6ece61fb8b55373823d

I expected this to lead to a page with transaction information.

The next link in the section leads to a page with transaction information as expected.

Links for next doc, previous doc

There should probably be at the beginning and end of each page a link to the previous doc and the next doc, that are local links that work correctly with github. Pages should be renamed first, as per #1.

Add emoji to blockquotes to make them stand out more

Inspired by something this repository does I want to propose adding emoji to the various blockquotes in order to make them stand out more (... than just the bold signal word). Another example of where this can be really beneficial is e.g. Chapter 6 section 4 Write our Transaction where at the end two consecutive blockquotes appear. Without the emoji this may appear as a single thing, and the emoji can help readers more easily distinguish between the two.

In the table below I present a preview of what I mean, compared to the current situation, with examples from various chapters. Of course, the emojis I picked are also up for debate.

I'm curious to hear what peoples opinions are about adding this to this project.

Current Updated Source

NOTE: This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for learning.

ℹ️ NOTE: This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for learning.

Chapter 3.1

WARNING: The btcblock alias will not work correctly if you try to place it in your .bash_profile by hand, rather than using the...

⚠️ WARNING: The btcblock alias will not work correctly if you try to place it in your .bash_profile by hand, rather than using the...

Chapter 3.1

VERSION WARNING: This is an innovation from Bitcoin Core v 0.14.0. If you used our setup scripts, that's what you...

⬆️ VERSION WARNING: This is an innovation from Bitcoin Core v 0.14.0. If you used our setup scripts, that's what you...

Chapter 4.3

TESTNET vs MAINNET: Remember that this tutorial generally assumes that you are using testnet. The btcblock...

🔗 TESTNET vs MAINNET: Remember that this tutorial generally assumes that you are using testnet. The btcblock...

Chapter 3.1

As for the Sequence note (e.g. in Chapter 4 section 2 Verify Your Raw Transaction) I'm really lost on what emoji should be used (and related to the last part of this issue, if it should even be a blockquote).


Related to this, I feel like the "M-OF-N VS N-OF-N" blockqoute in (e.g.*) chapter 6 section 1 Create the Addres is inconsistent with other usages of block quotes. But that might just be me 😄

* there is a similar one in Chapter 6 section 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.