Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: BitCoinDream on July 15, 2014, 03:23:45 PM



Title: Any PHP script that would do this ?
Post by: BitCoinDream on July 15, 2014, 03:23:45 PM
1. Generate a random bitcoin address.

2. Will check it's own address balance and confirmation at some of the existing block explorer service at a certain time interval using API call.

3. When a balance is found on the address with n+ confirmation, it pushes a Tx in network forwarding the balance to a certain address.

4. Make a call to a function amountSent with amount in satoshi and Tx ID as input, i.e. amountSent(amount, txid).


Title: Re: Any PHP script that would do this ?
Post by: grue on July 15, 2014, 03:46:04 PM
As in, a script that you can copy paste? probably not. but there's scripts for doing each of the steps you mentioned.


Title: Re: Any PHP script that would do this ?
Post by: AuroraHF on July 15, 2014, 03:48:44 PM
This would be really simple to create, I'm sure someone with a few months of coding can whip this up quickly using Blockchain's JSON-RPC API.


Title: Re: Any PHP script that would do this ?
Post by: BitCoinDream on July 15, 2014, 04:10:17 PM
As in, a script that you can copy paste? probably not. but there's scripts for doing each of the steps you mentioned.

Can u please at least point me to the address generation and Tx creation PHP script ? For Tx creation function, the i/p will be address and private key.


Title: Re: Any PHP script that would do this ?
Post by: BitCoinDream on July 15, 2014, 04:16:06 PM
This would be really simple to create, I'm sure someone with a few months of coding can whip this up quickly using Blockchain's JSON-RPC API.

The whole thing can be done using blockchain.info receive API in a single call. But, there are associated problems. Sometimes, when it takes more than 20 minutes to find a block, blockchain.info API takes looooooong time to forward the balance and does not make the callback at all !!! Hence, I'm trying to get rid of the blockchain.info dependency for receival purpose. If the code can be found or I can make it up by adding multiple snippets, it would probably help the community in general to partly move out of blockchain.info dependency for payment receival.


Title: Re: Any PHP script that would do this ?
Post by: ThomasCrowne on July 16, 2014, 06:21:41 AM
As in, a script that you can copy paste? probably not. but there's scripts for doing each of the steps you mentioned.

Can u please at least point me to the address generation and Tx creation PHP script ? For Tx creation function, the i/p will be address and private key.
Here ya go :)

https://github.com/mikegogulski/bitcoin-php/blob/master/src/bitcoin.inc#L567


Title: Re: Any PHP script that would do this ?
Post by: deathmare on July 16, 2014, 06:32:35 AM
Yeah, this can be done quickly by daemon's JSON-RPC API nor with command-line interface. Also I prepared something like you want with nodejs and blockchain.info before, not so hard to do in my opinion.


Title: Re: Any PHP script that would do this ?
Post by: BitCoinDream on July 16, 2014, 02:19:53 PM
As in, a script that you can copy paste? probably not. but there's scripts for doing each of the steps you mentioned.

Can u please at least point me to the address generation and Tx creation PHP script ? For Tx creation function, the i/p will be address and private key.
Here ya go :)

https://github.com/mikegogulski/bitcoin-php/blob/master/src/bitcoin.inc#L567

Thank u for the link. From a quick look, what I understand that it relies on JSON-RPC call to a BitcoinD to generate a new address. I'm not looking for that. I am looking for a PHP code that can generate a Bitcoin address & Private key combination without relying on any external call.


Title: Re: Any PHP script that would do this ?
Post by: deathmare on July 17, 2014, 07:40:22 AM
I'm not sure about that, but it looks PHP can not generate BTC addresses itself:
https://github.com/bitcoin/bitcoin/blob/d3165ed35adde59bdfbe72928b51a039202fa21e/src/rpcwallet.cpp#L79


Title: Re: Any PHP script that would do this ?
Post by: fbueller on July 17, 2014, 08:01:02 AM
My library borrows some stuff from Mikes (Or else Mikes borrows from an upstream one).

https://github.com/Bit-Wasp/bitcoin-lib-php/blob/master/src/BitcoinLib.php#313-328 This function generates a key pair + address.

The library doesn't use RPC calls, it's up to you to know what to use it for! You'd need either blockchains API or else some sort of transaction scraper to identify payments your addresses. A scraper gets complicated, since you need to be prepared for reorgs.


Title: Re: Any PHP script that would do this ?
Post by: BitCoinDream on July 17, 2014, 10:23:48 AM
I'm not sure about that, but it looks PHP can not generate BTC addresses itself:
https://github.com/bitcoin/bitcoin/blob/d3165ed35adde59bdfbe72928b51a039202fa21e/src/rpcwallet.cpp#L79

Before, I have seen a code by Theymos in Python that can independently generate an address. Moreover, given the fact that Bitcoin-QT is written in C++ and generating address independently, PHP should also be able to do the same. It is about taking a big random no. and doing some cryptographic transformation on it to generate private key and address.


Title: Re: Any PHP script that would do this ?
Post by: BitCoinDream on July 17, 2014, 10:24:27 AM

My library borrows some stuff from Mikes (Or else Mikes borrows from an upstream one).

https://github.com/Bit-Wasp/bitcoin-lib-php/blob/master/src/BitcoinLib.php#313-328 This function generates a key pair + address.

The library doesn't use RPC calls, it's up to you to know what to use it for! You'd need either blockchains API or else some sort of transaction scraper to identify payments your addresses. A scraper gets complicated, since you need to be prepared for reorgs.

In your code, as I can see, to get new private key, the following are being used...

Code:
\SECcurve::generator_secp256k1()
openssl_random_pseudo_bytes(32)

The second is in PHP lib, but is the first one ? If not, then how the first one is invoked ? I'm a little confused !!!

And, I'm not relying on a scraper to identify payment. Now, we have, multiple block explorers for bitcoin. We can check any address balance using their API and verify from multiple explorers.


Title: Re: Any PHP script that would do this ?
Post by: Eyepawd on July 17, 2014, 01:46:33 PM
Can't you just use RPC with Bitcoind
https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list

Bitcoind also has a function that will run a command when a transaction has been made.
https://en.bitcoin.it/wiki/Running_Bitcoin


Title: Re: Any PHP script that would do this ?
Post by: fbueller on July 17, 2014, 02:05:28 PM

My library borrows some stuff from Mikes (Or else Mikes borrows from an upstream one).

https://github.com/Bit-Wasp/bitcoin-lib-php/blob/master/src/BitcoinLib.php#313-328 This function generates a key pair + address.

The library doesn't use RPC calls, it's up to you to know what to use it for! You'd need either blockchains API or else some sort of transaction scraper to identify payments your addresses. A scraper gets complicated, since you need to be prepared for reorgs.

In your code, as I can see, to get new private key, the following are being used...

Code:
\SECcurve::generator_secp256k1()
openssl_random_pseudo_bytes(32)

The second is in PHP lib, but is the first one ? If not, then how the first one is invoked ? I'm a little confused !!!

And, I'm not relying on a scraper to identify payment. Now, we have, multiple block explorers for bitcoin. We can check any address balance using their API and verify from multiple explorers.

Clone the project from Github, or download the zip file: https://github.com/Bit-Wasp/bitcoin-lib-php

You can use composer (https://github.com/Bit-Wasp/bitcoin-lib-php/blob/master/README.md#installation) to manage all this. Install, and then include "./vendor/autoload.php"

Check the examples folder on how to use it then!