Bitcoin Forum
September 11, 2025, 01:27:29 PM *
News: Latest Bitcoin Core release: 29.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Help with RPC to wallet (bitcoind), Perl  (Read 1522 times)
Fizpok (OP)
Sr. Member
****
Offline Offline

Activity: 344
Merit: 250


View Profile WWW
May 17, 2013, 09:34:49 AM
 #1

Here:
https://blockchain.info/api/json_rpc_api

we can see an example of using bitcoind to contact another, remote wallet:
$ ./bitcoind -rpcconnect=rpc.blockchain.info -rpcport=443 -rpcssl -rpcuser=YourWalletIdentifier -rpcpassword=YourPassword getinfo

Now, I am trying to use Perl CGI, running on one howt, and accessing the wallet on another host (on blockchain.info):


use JSON::RPC::Client;
use Data::Dumper;
 
my $client = new JSON::RPC::Client;
 
  $client->ua->credentials(
     'localhost:8332', 'jsonrpc', 'user' => 'password'  # REPLACE WITH YOUR bitcoin.conf rpcuser/rpcpassword
      );
 
  my $uri = 'http://localhost:8332/';
  my $obj = {
      method  => 'getinfo',
      params  => [],
   };
 
  my $res = $client->call( $uri, $obj );
 
  if ($res){
      if ($res->is_error) { print "Error : ", $res->error_message; }
      else { print Dumper($res->result); }
  } else {
      print $client->status_line;
  }


Could you please help me to edit this Perl script, to move parameters (like url/port etc) from the command line to the script, so that the script could access the wallet, AND it was done using secure connection?

My second question is less urgent, but still: JSON::RPC::Client seems to be obsolete in Perl. Are there new alternatives to the code above?

Ethereum Programming Guide
Create Solidity contracts: Step-by Step Hands-on Guides.
Fizpok (OP)
Sr. Member
****
Offline Offline

Activity: 344
Merit: 250


View Profile WWW
May 17, 2013, 02:33:51 PM
 #2

Anyone?

Ethereum Programming Guide
Create Solidity contracts: Step-by Step Hands-on Guides.
dserrano5
Legendary
*
Offline Offline

Activity: 1974
Merit: 1036



View Profile
May 17, 2013, 08:19:33 PM
 #3

Could you please help me to edit this Perl script, to move parameters (like url/port etc) from the command line to the script

Use Getopt::Long:

Code:
$ cat getopt-rpc.pl 
#!/usr/bin/perl

use warnings;
use strict;
use Term::ReadKey;
use JSON::RPC::Client;
use Getopt::Long;

GetOptions \my %opts,
    '--host=s',
    '--port=s',
    '--user=s' or
    die 'getopt';

print 'RPC password: ';
ReadMode 'noecho'; $opts{'pass'} = <>; ReadMode 'restore'; print "\n";
chomp $opts{'pass'};

my $url = sprintf 'http://%s:%s@%s:%s/', @opts{qw/user pass host port/};

my $rpc = JSON::RPC::Client->new;
$rpc->prepare ($url, [ qw/getblock getblockhash/ ]);
my $bh = $rpc->getblockhash (222222);
my $block = $rpc->getblock ($bh);
my @tx = @{ $block->{'tx'} };
printf "%d txs\n", scalar @tx;

$ ./getopt-rpc.pl --user user --host localhost --port 8332
RPC password:
749 txs
$ ./getopt-rpc.pl -u user -h localhost -p 8332   ## short options are ok too
RPC password:
749 txs

Regarding the SSL bit, I lack motivation.
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!