You can do what you describe once you do it all with raw transactions, and if you run a full node (txindex=1)
So: you have an unsigned transaction, and a private key. You do not wish to save the private key to the wallet.
Decode the raw transaction, loop through the TxIn's.
- Do decoderawtransaction(getrawtransaction()) on each txid/vout, and then obtain the scriptPubKey for that specific output. You need an array, which has a child array containing (txid, vout, scriptPubKey) for each input.
Now you have the raw transaction and the inputs. You are supplying a WIF private key, so this needs to be put into an array in your application (not directly as a string).
This example in PHP assumes you have a full node, and $btc - a jsonrpcclient object connected to a bitcoin daemon.
$raw_tx = 'your unsigned raw transaction';
$decode = $btc->decoderawtransaction($raw_tx);
// Build inputs - a full node can get/decode arbitrary transactions
$inputs = array();
foreach($decode['vin'] as $vout => $txin) {
$old_txn = $btc->decoderawtransaction($btc->getrawtransaction($txin['txid']));
$scriptPubKey = $old_txn['vout'][$txin['vout']]['scriptPubKey'];
$inputs[] = array('txid' => $txin['txid'], 'vout' => $vout, 'scriptPubKey' => $scriptPubKey);
}
// Build privkeys array.
$privKeys = array('5L...........');
$sign = $btc->signrawtransaction($raw_tx, $inputs, $privKeys);
I'm sorry I didn’t know that this thread could be interesting for somebody, but now I'm back:
@fbueller: thanks for your help, but before I can setup a raw transaction process I have to get the latest "unspent coins" right?
Example:
$btc->listunspent(); //gives me the txIds, vout and scriptPubKey witch are required by the raw-transaction functions
//now I can call the several rawtransfer-functions to initiate a raw transaction, just like your code is doing that
But, listunspent gives me always a blank result unless I have imported the private key of an address and assigned that to an account. Here is my problem.
I've already tried to submit an address without the private key with:
$btc->setaccount('MYADDRESS', 'nameofmyAccount');
But the listunspent() always gave me a blank result. Maybe I doing something wrong, but in my opinion it is always required to import the private key right?
Unfortunately bitcoind will not tell you if the key was invalid. $sign contains a 'complete' index, which only changes from false -> true when the transaction is FULLY signed.
Why do you want to do signing on the server side? This means you're assuming full control of the coins, or asking people to divulge private keys. You could write a nice JS solution where they just enter a passphrase, which is converted to a seed, and you have them derive a particular key. then they sign client side and submit the transaction to you?
What are you hoping to write?
Well a seed-key-solution could be a good try. Now I'm still fighting with the bitcoind json-rpc-api key management is far away.