Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: CounterEntropy on September 01, 2015, 11:56:57 PM



Title: How do I create raw Tx using PHP ?
Post by: CounterEntropy on September 01, 2015, 11:56:57 PM
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 ?


Title: Re: How do I create raw Tx using PHP ?
Post by: ca333 on September 02, 2015, 06:59:37 AM
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-php
is 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.php

thank 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)#PHP
https://en.bitcoin.it/wiki/Raw_Transactions
https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list