3

So I just started writing a rails app that will be an online wallet. I'm looking over the API code examples for connecting to the bitcoin network at https://en.bitcoin.it/wiki/API_reference_(JSON-RPC).

PHP was the easiest example, seen here

  require_once 'jsonRPCClient.php';

  $bitcoin = new jsonRPCClient('http://user:[email protected]:8332/');

  echo "<pre>\n";
  print_r($bitcoin->getinfo()); echo "\n";
  echo "Received: ".$bitcoin->getreceivedbylabel("Your Address")."\n";
  echo "</pre>";

So I'm presuming that it connects to the bitcoin network via a username and password. Couple of questions.

What username/password? I bought bitcoin on coinbase, then exported it to a paper wallet. What user/pass is associated with my bitcoin? I thought it was just public/private key?

Why port 8332?

Why 127.0.0.1? Could it be any address?

1
  • Pick any username and password that you want. The values are used only for RPC connections. Port 8332 is the default port used by bitcoin for RPC connections and 127.0.0.1 is the localhost address (that is, connecting to 127.0.0.1 means you are connecting to a service running on the local system). You can change the port number if you have a conflict on your system by specifying rpcport in bitcoin.conf. Dec 10, 2013 at 16:47

1 Answer 1

1

You need to run either Bitcoin-Qt or bitcoind on your system. Create a bitcoin.conf file containing the following lines:

rpcuser=your-userid
rpcpassword=your-password
server=1

You can then connect to your bitcoin node by specifying address 127.0.0.1 and port 8332. Use the userid and password you specified in the bitcoin.conf file.

While it is possible to open port 8332 to allow remote users to connect to the local node, this is not a good idea for security reasons because it allows access to your wallet. Instead, your users would communicate with your application and your application would then make the necessary RPC calls to the local node.

2
  • Thanks Ron, that makes sense. So if I wanted to create a wallet service, where each user creates their own account on my site, and each account is associated with a wallet, then I'd have to have multiple wallets on my server right? One for each user? Dec 5, 2013 at 16:13
  • A single wallet can have multiple bitcoin addresses. So you would generate a bitcoin address for each user to allow them to send coins to their account. Partial withdrawals would be handled by sending the change back to the receive address or to a new change address. For the strongest security, bitcoin addresses should not be reused. So your application should allow users to create new addresses as needed. Your application would then need a database to associate bitcoin addresses with user accounts. Dec 5, 2013 at 16:33

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.