Bitcoin Forum
May 14, 2024, 05:08:23 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How do I create raw Tx using PHP ?  (Read 1143 times)
CounterEntropy (OP)
Full Member
***
Offline Offline

Activity: 214
Merit: 278


View Profile
September 01, 2015, 11:56:57 PM
 #1

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 ?
ca333
Hero Member
*****
Offline Offline

Activity: 520
Merit: 522


Developer - EthicHacker - BTC enthusiast


View Profile
September 02, 2015, 06:59:37 AM
Last edit: September 02, 2015, 07:18:37 AM by ca333
Merited by xandry (3), joniboini (2)
 #2

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

this space is available (free) for humanitarian nonprofit organizations - please contact me
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!