Author

Topic: How to read wallet.dat in PHP? (Read 869 times)

sr. member
Activity: 330
Merit: 250
April 03, 2014, 05:36:19 PM
#2
You should probably check out the source of PyWallet. Or the client.
full member
Activity: 191
Merit: 100
March 23, 2014, 12:23:38 PM
#1
I am trying to read content of wallet.dat in PHP and I have search around and it seems surprisingly no one has mention it before.

I have this code which I am trying to loop around all the key/values in wallet.dat but I only get one key, "main". I guess main seems to be logical db name. ( https://github.com/bitcoin/bitcoin/blob/v0.9.0/src/db.cpp#L260 ) Do anyone know why it only finds main and not other key/values? The wallet is unencrypted.

Code
Code:
print_r(dba_handlers(true));

$id dba_popen("wallet.dat""r""db4");

if (!
$id) {
    echo 
"dba_open failed\n";
    exit;
}

$key dba_firstkey($id);
$keys = array();
while (
$key != false) {
    
$value dba_fetch($key$id);
    
$keys[] = array($key$value);
    
$key dba_nextkey($id);
}

print_r($keys);

dba_close($id);

Output
Code:
Array
(
    [db4] => Berkeley DB 4.8.24: (August 14, 2009)
)
Array
(
    [0] => Array
        (
            [0] => main
            [1] => 
        )

)

I ran this in XAMPP 1.7.3 which has PHP 5.3.1 and php_dba.dll
Jump to: