Bitcoin Forum
May 07, 2024, 11:57:10 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: C++ code interacting with bitcoind  (Read 938 times)
glambeth (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
March 12, 2015, 12:42:55 AM
 #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?
1715083030
Hero Member
*
Offline Offline

Posts: 1715083030

View Profile Personal Message (Offline)

Ignore
1715083030
Reply with quote  #2

1715083030
Report to moderator
1715083030
Hero Member
*
Offline Offline

Posts: 1715083030

View Profile Personal Message (Offline)

Ignore
1715083030
Reply with quote  #2

1715083030
Report to moderator
"The nature of Bitcoin is such that once version 0.1 was released, the core design was set in stone for the rest of its lifetime." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715083030
Hero Member
*
Offline Offline

Posts: 1715083030

View Profile Personal Message (Offline)

Ignore
1715083030
Reply with quote  #2

1715083030
Report to moderator
1715083030
Hero Member
*
Offline Offline

Posts: 1715083030

View Profile Personal Message (Offline)

Ignore
1715083030
Reply with quote  #2

1715083030
Report to moderator
1715083030
Hero Member
*
Offline Offline

Posts: 1715083030

View Profile Personal Message (Offline)

Ignore
1715083030
Reply with quote  #2

1715083030
Report to moderator
cakir
Legendary
*
Offline Offline

Activity: 1274
Merit: 1000


★ BitClave ICO: 15/09/17 ★


View Profile WWW
March 12, 2015, 12:52:21 AM
 #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


                  ,'#██+:                 
              ,█████████████'             
            +██████████████████           
          ;██████████████████████         
         ███████:         .███████`       
        ██████               ;█████'      
      `█████                   #████#     
      ████+                     `████+    
     ████:                        ████,   
    ████:    .#              █     ████   
   ;███+     ██             ███     ████  
   ████     ███'            ███.    '███, 
  +███     #████           ,████     ████ 
  ████     █████ .+██████: █████+    `███.
 ,███     ███████████████████████     ████
 ████     ███████████████████████'    :███
 ███:    +████████████████████████     ███`
 ███     █████████████████████████`    ███+
,███     ██████████████████████████    #███
'███    '██████████████████████████    ;███
#███    ███████████████████████████    ,███
████    ███████████████████████████.   .███
████    ███████████████████████████'   .███
+███    ███████████████████████████+   :███
:███    ███████████████████████████'   +███
 ███    ███████████████████████████.   ███#
 ███.   #██████████████████████████    ███,
 ████    █████████████████████████+   `███
 '███    '████████████████████████    ████
  ███;    ███████████████████████     ███;
  ████     #████████████████████     ████ 
   ███#     .██████████████████     `███+ 
   ████`      ;██████████████       ████  
    ████         '███████#.        ████.  
    .████                         █████   
     '████                       █████    
      #████'                    █████     
       +█████`                ██████      
        ,██████:           `███████       
          ████████#;,..:+████████.        
           ,███████████████████+          
             .███████████████;            
                `+███████#,               
Cryptowatch.com
Full Member
***
Offline Offline

Activity: 196
Merit: 103


View Profile WWW
March 13, 2015, 12:30:07 AM
 #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.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!