Pages:
Author

Topic: PHP script to create private key & public address (Read 5375 times)

full member
Activity: 224
Merit: 100
You can't kill math.
I am having issues getting this script to run. I can run it fine from the server but when I try to run it from the php function that i got from here: https://github.com/RobKohr/PHP-Bitcoin-Address-Creator/blob/master/lib/botg.sh

I get this output:
Code:
Array ( [0] => PrivateKey [1] => 111111111111111111111111111FXjQL6s [2] => PublicKey [3] => 1HT7xU2Ngenf7D4yocz2SAcnNLW7rK8d4E )

Still man? Sucks...
sr. member
Activity: 457
Merit: 250
I am having issues getting this script to run. I can run it fine from the server but when I try to run it from the php function that i got from here: https://github.com/RobKohr/PHP-Bitcoin-Address-Creator/blob/master/lib/botg.sh

I get this output:
Code:
Array ( [0] => PrivateKey [1] => 111111111111111111111111111FXjQL6s [2] => PublicKey [3] => 1HT7xU2Ngenf7D4yocz2SAcnNLW7rK8d4E )
hero member
Activity: 533
Merit: 501
If you are on ubuntu, try:

sudo apt-get install bc

I had to do this on one of my servers to get it to work.

Also, just check each of the commands executed in the script (it isn't too long). Check to see that you have each installed.

Let me know the results, and I will update the readme if you have a solution.
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
I've already set the permissions on the botg.sh file correctly. At first it wasn't outputting anything so I fixed the permissions and it started giving me a string of 1's for both the keys. The output looks like this:

PrivateKey
1111111111111111111111111111111111
PublicKey
1111111111111111111111111111111111

I did a quick Google search and found that someone else using the BOTG script was getting the same type of output. It was because they were missing certain packages, so I assume that's my problem.
hero member
Activity: 533
Merit: 501
I created a php library that uses "bitcoin-off-the-grid" (BOTG) (source: https://bitcointalk.org/index.php?topic=23081.20) which is a bash script.

Here is the library:
https://github.com/RobKohr/PHP-Bitcoin-Address-Creator

I trimmed out a bunch of stuff from BOTG to make it more script friendly, and wrapped a php exec call to it. It seems to work pretty well.
Awesome idea, I didn't think of that. It's still not working on my server though, I must be missing some packages. It's just outputting a bunch of 1's for me. And I don't really have the ability to install new packages on my server, that's another reason I wanted to find a way to generate bitcoin addresses without installing bitcoind on the server. I tried grondilu's Perl modification which removes some dependencies, but no luck. I must be missing the dc/bc package. Looks like I might have to read up on the process for creating bitcoin addresses and write a pure PHP script.
Go into lib and
chmod 777 botg.sh

then do this:
./botg.sh

Tell me what happens.

legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
I created a php library that uses "bitcoin-off-the-grid" (BOTG) (source: https://bitcointalk.org/index.php?topic=23081.20) which is a bash script.

Here is the library:
https://github.com/RobKohr/PHP-Bitcoin-Address-Creator

I trimmed out a bunch of stuff from BOTG to make it more script friendly, and wrapped a php exec call to it. It seems to work pretty well.
Awesome idea, I didn't think of that. It's still not working on my server though, I must be missing some packages. It's just outputting a bunch of 1's for me. And I don't really have the ability to install new packages on my server, that's another reason I wanted to find a way to generate bitcoin addresses without installing bitcoind on the server. I tried grondilu's Perl modification which removes some dependencies, but no luck. I must be missing the dc/bc package. Looks like I might have to read up on the process for creating bitcoin addresses and write a pure PHP script.
hero member
Activity: 533
Merit: 501
0.6 doesn't exist.
hero member
Activity: 742
Merit: 500
It might be easier to hook into bitcoind's rpc for creating new addresses rather than rewriting client code in PHP. This means your webserver would need access to a bitcoind, but not necessarily one that is even connected to the network.  It could just be for address generation.  You could export the keys generated and set them up to be swept by a different bitcoind that can't be compromised by your webserver.

That would be another service to run on a webserver which is a bit heavy duty. Also, getting all the private keys out of it would require using pywallet to export them, and then reimport them into your desktop wallet.

I created a php library that uses "bitcoin-off-the-grid" (BOTG) (source: https://bitcointalk.org/index.php?topic=23081.20) which is a bash script.

Here is the library:
https://github.com/RobKohr/PHP-Bitcoin-Address-Creator

I trimmed out a bunch of stuff from BOTG to make it more script friendly, and wrapped a php exec call to it. It seems to work pretty well.

Bitcoin 0.6 has the import/export built in so that won't be a problem much longer.  Using botg is a good idea, too.
hero member
Activity: 533
Merit: 501
It might be easier to hook into bitcoind's rpc for creating new addresses rather than rewriting client code in PHP. This means your webserver would need access to a bitcoind, but not necessarily one that is even connected to the network.  It could just be for address generation.  You could export the keys generated and set them up to be swept by a different bitcoind that can't be compromised by your webserver.

That would be another service to run on a webserver which is a bit heavy duty. Also, getting all the private keys out of it would require using pywallet to export them, and then reimport them into your desktop wallet.

I created a php library that uses "bitcoin-off-the-grid" (BOTG) (source: https://bitcointalk.org/index.php?topic=23081.20) which is a bash script.

Here is the library:
https://github.com/RobKohr/PHP-Bitcoin-Address-Creator

I trimmed out a bunch of stuff from BOTG to make it more script friendly, and wrapped a php exec call to it. It seems to work pretty well.
hero member
Activity: 742
Merit: 500
It might be easier to hook into bitcoind's rpc for creating new addresses rather than rewriting client code in PHP. This means your webserver would need access to a bitcoind, but not necessarily one that is even connected to the network.  It could just be for address generation.  You could export the keys generated and set them up to be swept by a different bitcoind that can't be compromised by your webserver.
hero member
Activity: 533
Merit: 501
Good point in favor of the "give every customer a new address" method.

I think reusing addresses is a bad idea and should be discouraged. Creating new addresses is free, and it makes it so their is no confusion as to who paid and who didn't. I basically use addresses as "order numbers" so that it is easy to relate an order to a payment.
legendary
Activity: 2646
Merit: 1138
All paid signature campaigns should be banned.
Good point in favor of the "give every customer a new address" method.
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
Quote
I think they were expecting you to move the BTC off the address each time so you can start back at zero for each re-use of the address. This would also work.
Wouldn't that involve a transaction fee for every single address that you need to empty?
hero member
Activity: 533
Merit: 501
I created a fork of pywallet which will import a text file of private keys into your wallet.
https://github.com/RobKohr/pywallet

The webserver could generate the pubs/privs and when you log in as an admin, you could download that private key list and import into your wallet. I would recommend that you delete the private keys on the webserver after you import them into your wallet.

legendary
Activity: 2646
Merit: 1138
All paid signature campaigns should be banned.
Quote
It seems having a new address for each customer is desirable, but wouldn't it be better to simply get new addresses via this method we're talking about rather than a 3rd party as the wiki suggests?
Yes, generating your own seems the best way to go.  Generate a key pair, give the public key address to the customer and import the private key into your wallet.

Quote
Also, it seems to me like the getreceivedbyaddress function returns the total amount sent to a specified address, so if you were re-using addresses wouldn't that mean you'd need to keep track of how much each address has received?
I think they were expecting you to move the BTC off the address each time so you can start back at zero for each re-use of the address.  This would also work.
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
lol don't worry I'm still confused. It's almost 4 in the morning here. Grin

I'm mainly just wondering if it would be better to use a list or to generate a new keypair for each customer.

I found this page on the wiki, and it's basically what I was talking about:

Quote
Solution for receiving bitcoins

1.    Input a list of bitcoin receiving addresses to your database
2.    Give a bitcoin address to a potential customer
3.    Have the customer tell you when they have sent the coins and have at least 1 confirmation (you can choose a number higher than 1 if you are worried about double-spending)
4.    Check blockexplorer to see if they sent the right amount (i.e. http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH/1) - the /1 is the number of confirmations you require
5.    Give them what they paid for
6.    After a reasonable amount of time has passed, you can re-use the address for another customer

You could avoid having a list of addresses and reusing them if one of the wallet services someday lets you get a new address via API call, but this will work for now.

It seems having a new address for each customer is desirable, but wouldn't it be better to simply get new addresses via this method we're talking about rather than a 3rd party as the wiki suggests?

Also, it seems to me like the getreceivedbyaddress function returns the total amount sent to a specified address, so if you were re-using addresses wouldn't that mean you'd need to keep track of how much each address has received?
legendary
Activity: 2646
Merit: 1138
All paid signature campaigns should be banned.
See my edit, sorry for the confusion.
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
Quote
Yes, your original post basically describs one "correct" way to do it - generate a keypair for each customer
Ok, so then this would be useful? Is this way more "correct" then using a static list of addresses?
legendary
Activity: 2646
Merit: 1138
All paid signature campaigns should be banned.
OK, now we have confused each other!  

Yes, you want to create a key pair for each customer who comes to your web site
Yes, you want to import the private key into your wallet (where ever you keep your wallet)
Yes, you want to monitor the block chain for payment
Yes, once payment is made you can ship your product
Yes, you can either import the private key before or after the payment is made (it does not make any difference)
Yes, your original post basically describes how to do this

Yes, I was confused by your original question and I hope we are on the same page now

Pages:
Jump to: