Bitcoin Forum
June 15, 2024, 12:48:58 AM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: HELP ! im going crazy  (Read 594 times)
imgoingcrazy (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 03, 2015, 04:31:26 PM
 #1

So im trying to import an private key to bitcoin using php... no luck in couple of hours

here is the script

<?php

/* Configuration variables for the JSON-RPC server */
$rpc_host = '127.0.0.1';
$rpc_port = '8332';
$rpc_user = 'root';
$rpc_pass = 'root123';
 set_time_limit(3600);

require_once('jsonRPCClient.php');
$bc = new jsonRPCClient('http://' . $rpc_user . ':' . $rpc_pass . '@' . $rpc_host . ':' . $rpc_port);

$bc->importprivkey("privatekey","root");
print_r($bc->getaddressesbyaccount($rpc_user));
$balance = $bc->getbalance()."\n";

echo $balance;
?>


here is the output

Warning: fopen(http://...@127.0.0.1:8332): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in C:\xampp\htdocs\jsonRPCClient.php on line 132

Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to http://root:root123@127.0.0.1:8332' in C:\xampp\htdocs\jsonRPCClient.php:140 Stack trace: #0 C:\xampp\htdocs\test.php(13): jsonRPCClient->__call('importprivkey', Array) #1 C:\xampp\htdocs\test.php(13): jsonRPCClient-
coinpr0n
Hero Member
*****
Offline Offline

Activity: 910
Merit: 1000



View Profile
December 03, 2015, 04:59:55 PM
 #2

(I haven't used the PHP client but) I suppose you're using the correct rpcuser and rpcpassword as set in your bitcoin.conf file. Can you execute other RPC commands? Is privatekey a valid private key? Maybe importprivkey takes an array?

imgoingcrazy (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 03, 2015, 05:07:00 PM
 #3

Yes other commands such getbalance , getinfo works. the private key is dumped with pywallet from wallet.dat also tried one private key dumped from blockchain .. same error.
jonnybravo0311
Legendary
*
Offline Offline

Activity: 1344
Merit: 1023


Mine at Jonny's Pool


View Profile WWW
December 04, 2015, 03:25:33 AM
 #4

Why are you trying to import a private key using php?  Just use the command line.  What possible use case is there for having a web page that can collect a private key and import it into your wallet (other than the obvious nefarious ones)?

Code:
bitcoin-cli importprivkey "yourkey"

Jonny's Pool - Mine with us and help us grow!  Support a pool that supports Bitcoin, not a hardware manufacturer's pockets!  No SPV cheats.  No empty blocks.
imgoingcrazy (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 04, 2015, 11:08:14 AM
 #5

If i wanted to use the command line i wouldn't ask for php code. stop spamming
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!