-1

I am reading the book "Mastering Bitcoin" from Antonopoulos and want to compile an example from that book. It does not tell which C++ library needs to be installed for #include <bitcoin/bitcoin.hpp> to work.

#include <bitcoin/bitcoin.hpp>

int main()
{
    // Private secret key.
    bc::ec_secret secret;
    bool success = bc::decode_base16(secret,
        "038109007313a5807b2eccc082c8c3fbb988a973cacf1a7df9ce725c31b14776");
    assert(success);
    // Get public key.
    bc::ec_point public_key = bc::secret_to_public_key(secret);
    std::cout << "Public key: " <> bc::encode_hex(public_key) << std::endl;
    
    // Create Bitcoin address.
    // ... further comments
    
    // Compute hash of public key for P2PKH address.
    const bc::short_hash hash = bc::bitcoin_short_hash(public_key);
    
    bc::data_chunk unencoded_address;
    // Reserve 26 bytes
    // ...
    unencoded_address.reseve(25);
    unencoded_address.push_back(0);
    bc::extend_data(unencoded_address, hash);
    bc::append_checksum(unencoded_address);
    assert(unencoded_address.size() == 25);
    const std::string address = bc::encode_base58(unencoded_address);
    
    std::cout << "Address: " << address << std::endl;
    return 0;
}

Compiling should be done like this:

g++ -o addr addr.cp $(pkg-config --cflags --libs libbitcoin)

Running ./addr should give output:

"Public key: ..."
"Address: ..."

Since there have been a lot of changes to the code base it is unclear what to do with the include. The one of the code is not availlable any more.

3
  • Why do you include that? What Bitcoin-related functions do you need? If they are in that library, how else do you propose the program could ever compile/run without having the library installed? This is too broad a question to answer really. Commented Sep 2, 2019 at 9:35
  • I can't find that header in any of the relevant repos on github. Which book is it? Does it really not say more about how the header should be acquired? Commented Sep 2, 2019 at 9:57
  • The book is: amazon.com/Mastering-Bitcoin-Unlocking-Digital-Cryptocurrencies/…. The code seems to be outdated. Commented Jul 10, 2020 at 12:27

2 Answers 2

4

Commit 83f36c901a3f45e8ab667f1db283d72e75a58176 of the libbitcoin/libbitcoin-system repository renamed bitcoin/bitcoin.hpp to bitcoin/system.hpp.

It looks like you can just install it with the typical ./autogen.sh && configure && make && make install steps. After that you can either create a copy of bitcoin/system.hpp or adapt your client code.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, I am relatively new to this. Is github.com/libbitcoin/libbitcoin-system something else than libbitcoin-server? I am a bit confused since both have the same parent but different install advices.
libbitcoin-server depends on libbitcoin-system. If you only need that header file (and whatever code it comes with), you should be able to get by with just libbitcoin-system.
I just realized that despite having different git sites both actually have identical installation advice and refer to the same wget source. Now I have to figure out why it is crashing my Raspberry. :)
Presumably that is to help people install the full set of libraries. I linked you to the 'autotool for advanced users' section, which is for just installing the -system library.
A lot of upvotes for this answer but my question is still negative. I appreciate any input on how to improve the question. At the moment, I am not allowed to ask more questions, also because the negative vote here. Thanks!
1

What I needed to install was the library libbitcoin or more precisely the "Bitcoin Cross-Platform C++ Development Toolkit" libbitcoin-system.

But since the best way to solve this was to use the automatic installation script for debian from here:

$ sudo apt-get install build-essential autoconf automake libtool pkg-config git
$ wget https://raw.githubusercontent.com/libbitcoin/libbitcoin/version3/install.sh
$ chmod +x install.sh
$ ./install.sh --prefix=/home/me/myprefix --build-boost --disable-shared

and this installed the whole libbitcoin system with all dependencies e.g. boost and secp256k1 it also installed libbitcoin-server.

Installing just parts of it as suggested in another answer did not work for me because of missing dependencies which I could not link properly.


Regarding the swap I can say that it worked fine with 4GB swapfile on external HDD although the RPi2 has just 20MB/s effective bandwith.


To be able to use the library I had to give the --static attribute when compiling my program:

g++ -o addr 69_addr2.cpp $(pkg-config --cflags --libs --static libbitcoin)

1 Comment

Hi, i when i am compiling example program like this ` #include <bitcoin/system.hpp> int main() { bc::ec_secret decoded; bc::decode_base16(decoded, "038109007313a5807b2eccc082c8c3fbb988a973cacf1a7df9ce725c31b");} ` i am getting error like undefined reference to libbitcoin::config::checkpoint::checkpoint`. Has the syntax of libbitcoin changed, or i am doing sth wrong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.