Author

Topic: C++ code interacting with bitcoind (Read 966 times)

full member
Activity: 196
Merit: 103
March 12, 2015, 07:30:07 PM
#3
If you want to work with notifications, you could enter something like this in bitcoin.conf:

walletnotify=/path/binary %s
blocknotify=/parth/binary %s

The binary could be a compiled C++ program that takes arguments.

For example, you could use popen to execute shell command from C++ in a binary triggered by one of the notify-events:

Code:
const string BITCOIND="/usr/bin/bitcoind -testnet -conf=/path/testnet.conf ";
string cmd=BITCOIND + " gettransaction " + txid + " 2>&1";
FILE* fp = popen(cmd.c_str(), "r");

Be aware that there might be security risks by running system commands from C++, and it is not generally advised, but it's a quick and dirty way to get things running for you.

Then you could proceed to manipulate the json data and do whatever further actions you need.

It's wise to use testnet when working with this, as you don't risk anything if you make a mistake, and you also do not pollute the blockchain with dust-transactions. There's also something called "testnet-in-a-box", not sure if it is updated and working anymore, but it used to work well before.

Edit: I noticed that in 0.10.0 you don't call bitcoind directly anymore, but use bitcoin-cli.

Good luck.

legendary
Activity: 1274
Merit: 1000
★ BitClave ICO: 15/09/17 ★
March 11, 2015, 07:52:21 PM
#2
You need to interact with bitcoind via RPC.
Here's an open source sample that may help you: https://github.com/bytemaster/cpp_bitcoin_rpc
newbie
Activity: 2
Merit: 0
March 11, 2015, 07:42:55 PM
#1
Hi, I've been trying to find an example of how I could use a c++ program to execute bitcoin api calls. Does anyone know some examples I'm doing this solely for the purpose of learning. I found the bitcoind client API call list here https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list but I'm unsure how I would execute these commands as they are written in the bitcoin scripting language. Would I just want to use the system command? Any ideas on some project recommendations or some exercises that would be worthwhile?

If i'm interested in learning this I'm guessing I should pickup the scripting language is that a worthwhile endeavor?
Jump to: