I have the following data in MySQL table...
Address1 - PrivKey1 - Amount1
Address2 - PrivKey2 - Amount2
Address3 - PrivKey3 - Amount3
I can get the list of unspent outputs from blockchain.info API -
https://blockchain.info/unspent?active=Address1|Address2|Address3
Now, I want a php script which will generate the raw Tx to spend all UTXO to an offline destination address, say dAddress, including the calculation of proper Tx fee, i.e. size of the raw Tx needs to be dynamically calculated. Can someone please help me out ?
If this is for production enviroment I
strongly recommend to get unspent outputs from
local blockchain (from your btc-node).
For your question: (simple solution)
https://github.com/Bit-Wasp/bitcoin-lib-phpis the library for BTC in php. all key functions are implemented there.
for your raw-tx look in this:
https://github.com/Bit-Wasp/bitcoin-lib-php/blob/master/src/RawTransaction.phpthank you,
ca333
#EDIT: you can also connect to btcdaemon with json rpc and then use bitcoin
functions on daemon. For your purpose you will need: listunspent, createrawtransaction, signrawtransaction, sendrawtransaction
usefull material:
https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#PHPhttps://en.bitcoin.it/wiki/Raw_Transactionshttps://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list