Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: flydrones on December 03, 2015, 02:56:15 PM



Title: How to generate Bitcoin-addressess with PHP?
Post by: flydrones on December 03, 2015, 02:56:15 PM
Hello Everyone  :)

I'm a total newbie with Bitcoin so forgive me if I'm asking stupid things. All help needed!

My plan is to implement a way to pay with Bitcoins in my webshop.
My problem is to generate bitcoin-adresses with PHP. How should I do that?

I already managed to use addrgen.php (from https://github.com/prusnak/addrgen (https://github.com/prusnak/addrgen)) but that needs a MPK in 64base. When I use Electrum or Bitcoin Core I do not have an 64base MPK, I have something else like this, these are examples:

Example (Electrum): xpub662MyMwAqRbcH1h5aJpdem6aJ4CVaWaab2vC8tv25aJpdeyKKsBpfeBPJjLwHdqcsxdHnVc4A9X aUDvfBzhfKJwYAaNTEHyTviwjwP2nCt2
or example (Bitcoin Core): L4zMahdeJLLsYNenP5XN9baV5bYKB2aiF9tTeHWrsYNenP9zBQGR


Any ideas how to:
 a) convert Electrum or Bitcoin Core private keys to 64base so that I can use this addrgen.php?
 b) some other PHP code sample that I can modify to produce limitless Bitcoin-adresses?
 c) some other idea?

All hints and ideas are welcome!
BIG thanks in advance!


Title: Re: How to generate Bitcoin-addressess with PHP?
Post by: cr1776 on December 03, 2015, 03:19:03 PM
One option is to just generate them in bulk - e.g. 50000 at a time on a different computer with bitcoin core or something - and then just reference the public keys from php.  Marking them as used as you go along (so you don't reuse them).   This also avoid exposing the private key to a web connected machine which could be considered a security risk.

You can also use bitcoin core as a backend and generate them there using php.  

It is difficult to code your own correctly due to the ease of introducing bugs (e.g. in the PRNG or elsewhere).  Sometimes it is more efficient and safer to use code that has been well tested.


Title: Re: How to generate Bitcoin-addressess with PHP?
Post by: jonnybravo0311 on December 03, 2015, 03:32:42 PM
Have your website make a call back to your bitcoin daemon to get a new address.  If you want to keep track of your customers (i.e. they've logged in and you know their user name) you can make a call like this:
Code:
$bitcoin->getnewaddress($username);


Title: Re: How to generate Bitcoin-addressess with PHP?
Post by: flydrones on December 03, 2015, 04:04:39 PM
Thank you for the answers. Thanks!

Creating the addresses in advance with my Electrum wallet is not impossble but kind of - somhow - not so fancy... Propably I have to do it like that. First creating 50,000 addresses, then copy them half-manually to MySQL and >boom!< it works  ;D

Have your website make a call back to your bitcoin daemon to get a new address.

Allright, I don't have the slightest clue what "bitcoin daemon" is  ???

If found this -> https://github.com/Bit-Wasp/bitcoin-lib-php and it should be able to create addresses from the BIP32 MPK. Unfortunatelly it's way too complicated for me now. Have to do some toughtfull reading.

I can't believe it is this hard to create addresses with PHP from BIP32! Big obstacle for me and many others, heh hee. I wish I hade a 64base MPK and could forget all this.


Title: Re: How to generate Bitcoin-addressess with PHP?
Post by: cakir on December 03, 2015, 04:08:53 PM
If you want to create fresh btc addresses (in bulk) you can use bitcoin core (Without syncing).
on the bitcoin.conf file just add this:
keypoolsize=10000

this will create 10k btc addresses. then you can dump this wallet and get these 10k address & priv keys.


Title: Re: How to generate Bitcoin-addressess with PHP?
Post by: flydrones on December 03, 2015, 04:37:06 PM
If you want to create fresh btc addresses (in bulk) you can use bitcoin core (Without syncing).
on the bitcoin.conf file just add this:
keypoolsize=10000
this will create 10k btc addresses.

Sounds great. Thank you very much!
But where is "bitcoin.conf"? I'm running a Bitcoin Core on OSX... Sorry, I'm not good on these things  ::)


then you can dump this wallet and get these 10k address & priv keys.
I get that, thanks, but what do you mean with "...& priv keys"?


Title: Re: How to generate Bitcoin-addressess with PHP?
Post by: cakir on December 03, 2015, 05:49:59 PM
If you want to create fresh btc addresses (in bulk) you can use bitcoin core (Without syncing).
on the bitcoin.conf file just add this:
keypoolsize=10000
this will create 10k btc addresses.

Sounds great. Thank you very much!
But where is "bitcoin.conf"? I'm running a Bitcoin Core on OSX... Sorry, I'm not good on these things  ::)


then you can dump this wallet and get these 10k address & priv keys.
I get that, thanks, but what do you mean with "...& priv keys"?
Sorry I use windows, don't know Mac, but you can find it here:
https://en.bitcoin.it/wiki/Running_Bitcoin#Bitcoin.conf_Configuration_File

I need to correct something. it's not keypoolsiz, it's "keypool=10000"

When you dump your wallet it gives you all the created bitcoin addresses and private keys;
For instance:
Code:
#this dump created on the date 03.12.2015
1address1 5privatekey
1address2 5privkey2
1adddres3 5privkey3

Make sure that you import only the public addresses. You should keep the private keys private.


Title: Re: How to generate Bitcoin-addressess with PHP?
Post by: jonnybravo0311 on December 03, 2015, 10:00:03 PM
If you want to create fresh btc addresses (in bulk) you can use bitcoin core (Without syncing).
on the bitcoin.conf file just add this:
keypoolsize=10000
this will create 10k btc addresses.

Sounds great. Thank you very much!
But where is "bitcoin.conf"? I'm running a Bitcoin Core on OSX... Sorry, I'm not good on these things  ::)


then you can dump this wallet and get these 10k address & priv keys.
I get that, thanks, but what do you mean with "...& priv keys"?
To answer your earlier question... bitcoin daemon is just the bitcoin process (to start it in linux you type: bitcoind).  Since you're on a Mac, I can certainly help you there :).  By default using the Bitcoin application on a Mac does not create a bitcoin.conf file.  You create your own.  When you first start up your Bitcoin application (assuming of course the standard Bitcoin Core software downloaded from bitcoin.org), it creates a directory here:
Code:
~/Library/Application Support/Bitcoin
It is in that directory that you want to create the bitcoin.conf file.


Title: Re: How to generate Bitcoin-addressess with PHP?
Post by: flydrones on December 05, 2015, 05:35:02 PM
 :)

Thanks for all the good advices! Thanks!
I got some pretty good codes now. I'll be soon back with more questions (be prepared!) - as soon as I get thru all this stuff  :)