-1

I'm new in RPC. I developed a board which use many coin to exchange . But my board is based on other website api to get the BTC address for users. And i want it to be independent. So i was searching and i found this that i can set up bitcoin daemon on the server and configure it using RPC (RPCuser, RPCpassword, RPCport ... etc) And then use javascript to connect my board to the bitcoin daemon to get every user his BTC wallet address. My problem is i'm new in RPC javascript development. So could you please give me a simple code of javascript using RPC to connect to Bitcoin daemon and get a new wallet address, balance, send and receive money, History ... etc.? I already installed Bitcoin daemon on my server and i ran it. I only left with the javascript code. This is my bitcoin.conf file information:

rpcuser=username
rpcpassword=mypassword 
rpcallowip=127.0.0.1
rpcallowip=xxx.xxx.xxx.xxx
rpcallowip=xxx.xxx.xxx.xxx
rpcport=8332
server=1
daemon=1
listen=1
txindex=1
galaxymini
  • 13
  • 5

2 Answers2

-1

You can use following command to make RPC call from terminal using cURL:

curl --user username --data-binary '{"jsonrpc": "1", "id":"", "method": "getblockchaininfo", "params": [] }' -H 'content-type: text/plain' http://localhost:8332/

It will prompt for password. You need to enter mypassword. You will get response as below.

{"result":{"chain":"main","blocks":516395,"headers":516395,"bestblockhash":"00000000000000000041e29f2cc8a69d58f5a697911aa00cac2f85e804dddbcc","difficulty":3511060552899.72,"mediantime":1522732888,"verificationprogress":0.9999903671792401,"initialblockdownload":false,"chainwork":"0000000000000000000000000000000000000000016983aead48f5850394132c","size_on_disk":538941354,"pruned":true,"pruneheight":515612,"automatic_pruning":true,"prune_target_size":629145600,"softforks":[{"id":"bip34","version":2,"reject":{"status":true}},{"id":"bip66","version":3,"reject":{"status":true}},{"id":"bip65","version":4,"reject":{"status":true}}],"bip9_softforks":{"csv":{"status":"active","startTime":1462060800,"timeout":1493596800,"since":419328},"segwit":{"status":"active","startTime":1479168000,"timeout":1510704000,"since":481824}},"warnings":""},"error":null,"id":""}

-1

I am using Node JS. You need to install npm for bitcoin.

Please find following code.

In Terminal

npm install bitcoin 

in AppRoutes File:

var bitcoin = require('bitcoin');
var client = new bitcoin.Client({
 host: Your IP Address of Node,
 port: 18332,
 user: UserName,
 pass: Password
});

app.post("/chainInfo", function(req, res) {

   console.log('BlockChainInfo: need');
   client.getBlockchainInfo(function(err, info) {
     if (err) {
       console.log('info: completed');
       return console.error(err);
     }else{
       console.log('info: ' + info);
       res.send(info);
     }
   });
});