Search code examples
perlbitcoinbitcoind

Using Bitcoin's sendmany function with perl


I have been struggling with this one for a while and will be grateful if someone could offer a solution. Basically, I am trying to use bitcoin's 'sendmany' function (https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list) to send mass payment with a perl script. I am running bitcoind on a vps and other functions are working fine but sendmany isn't. This is the code that I have :

use Finance::Bitcoin::API;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
use Data::Dumper;
my %recipients = ("ADDRESS1" => sprintf("%.8f",0.00005460)+0, "ADDRESS2" => sprintf("%.8f",0.00005460)+0);
my $uri     = "https://$rpcuser:$rpcpass\@$rpcip:8332/";
my $api     = Finance::Bitcoin::API->new( endpoint => $uri );
my $action  = $api->call('sendmany','',%recipients);
if ($api->error)
{
    print Dumper($api->error->{message})."\n";
}
else
{
    print Dumper($action)."\n";
}

I am able to send single payments using the 'sendtoaddress' function and I am able to use the sendmny function directly in the vps that is running bitcoind by executing it from the shell, but it fails when I try it using the perl script above. There is no error message, I just get the instructions for using sendmany from shell and using curl.

I am also open to scripts in any other language that will let me execute sendmany.

Thanks for the help.


Solution

  • I finally figured out the error in the above code. Replace the line my $action = $api->call('sendmany','',%recipients); with my $action = $api->call('sendmany','',\%recipients);

    Basically just add a forward slash before %recipients. Hope this helps someone.