Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: dacoinminster on March 09, 2011, 06:04:10 PM



Title: Bitcoin API - solved!
Post by: dacoinminster on March 09, 2011, 06:04:10 PM
I have a bunch of bitcoin-powered website ideas I would love to work on. I have reasonable PHP/MySQL skills, but I'm not sure what is the best way to interface a website with bitcoin. I poked through the forums and found a couple different ways this might be done, but I'm not sure what is the simplest solution to just get something working.

Options:

1) bitcoind - I think this might be the same as configuring bitcoin to run as server. I believe it uses an RPC API to run transactions from the command line.
Pros: Everything stays on my server
Cons: I have to find a server that will let me compile and install this, rather than just some PHP/MySQL farm in the cloud, which is what I prefer

2) mybitcoin.com "shopping cart interface".
Pros: Seems to do everything I would need
Cons: I don't see anybody talking about using it. (Can anybody tell me how well this works?). Also have to install/compile/run something on my server, rather than just constructing/posting a URL and reading the results, which is what I prefer.

3) mtgox.com API:
Pros: Perfect API model (construct/post a URL, then read the results)
Cons: According to the documentation, I can send bitcoins via the API, but I don't see any way to generate a new address and then query if bitcoins have been received at that address. If I could do that, it would be perfect!

4) Manually parse webpage at mybitcoin.com or mtgox.com
Pros: I know how to do this
Cons: It would take a lot longer, it would be hacky, it would break when the webpage changed, and I'd have to find some way around the captcha at mybitcoin.com if I used that site

What do you guys (who have bitcoin-powered websites) do? If there is a really stupid-simple API to handle bitcoins from my webpage without installing anything, I've missed it.

Any help would be appreciated. I would like to point out that if such an API existed and was widely used/known, the difficulty in creating a new bitcoin-powered site would go down significantly.

Edit:

Thanks for the comments everyone. It looks like what I want doesn't exist yet, so I'll offer a small bounty: 20BTC

Payable to the first online wallet service (new or existing) who provides the world with a URL API something like this:

https://www.coolservice.com?user=dacoinminster&pwd=mypassword&action=spend&address=bitcoin_address_to_send_to&amount=#
(an equivalent one for this already exists at mtgox)

https://www.coolservice.com?user=dacoinminster&pwd=mypassword&action=getnewaddress
(returns new bitcoin address which I can give to a customer)

https://www.coolservice.com?user=dacoinminster&pwd=mypassword&action=seecoins
(returns my BTC balance)

https://www.coolservice.com?user=dacoinminster&pwd=mypassword&action=seecoins&address=bitcoin_address_of_mine
(returns number of BTC sent to that address, and number of confirmations received so far)

https://www.coolservice.com?user=dacoinminster&pwd=mypassword&action=seetransactions
(returns all my transactions ever, with addresses and # of confirmations for each one)

Bounty is only payable if the service is free to everyone. Website must be either already trusted, or must establish a trustworthy reputation. Hopefully others interested in having a service like this will add to my little bounty.

Edit: Problem solved, and bounty expired paid: http://bitcointalk.org/index.php?topic=4324.msg77187#msg77187


Title: Re: Bitcoin API
Post by: mndrix on March 09, 2011, 06:41:47 PM
1) bitcoind - I think this might be the same as configuring bitcoin to run as server. I believe it uses an RPC API to run transactions from the command line.
Pros: Everything stays on my server
Cons: I have to find a server that will let me compile and install this, rather than just some PHP/MySQL farm in the cloud, which is what I prefer

This is what I use for CoinPal, CoinCard and JJGames.  I like having local control of my Bitcoins and getting access to all the APIs bitcoind provides.  Several times I've found it valuable to use `minconf` options when calculating balances and payments received.  I also use the `listtransactions` API frequently.  I don't think those are available in any of the other APIs you mention.

Quote
3) mtgox.com API:
Pros: Perfect API model (construct/post a URL, then read the results)
Cons: According to the documentation, I can send bitcoins via the API, but I don't see any way to generate a new address and then query if bitcoins have been received at that address. If I could do that, it would be perfect!

I do a lot of work with the Mt. Gox APIs and they're excellent.  However, I wouldn't personally want to run a Bitcoin business using them alone because they don't provide enough access to the low-level details.

If you do find a Mt. Gox API for creating new Bitcoin addresses and querying when coins have arrived, let me know.  It would be convenient for me too.


Title: Re: Bitcoin API
Post by: Gavin Andresen on March 09, 2011, 07:18:53 PM
1) bitcoind - I think this might be the same as configuring bitcoin to run as server. I believe it uses an RPC API to run transactions from the command line.
Pros: Everything stays on my server
Cons: I have to find a server that will let me compile and install this, rather than just some PHP/MySQL farm in the cloud, which is what I prefer

You can run the front-end on one server and the back-end on another (and communicate via JSON-RPC over HTTPS).  That's how I'm able to run the Faucet and ClearCoin on Google's App Engine (they talk with bitcoind processes running on linode.com and aws.amazon.com servers).  bitcoind doesn't take much memory, bandwidth, or CPU (just don't turn on coin generation), so, for now, anyway, you can even use an Amazon "micro" server (which costs something like $100 per year).

I'm not selling anything so can't comment on the shopping cart interfaces.  Screen-scraping web pages is a bad idea for lots of reasons.


Title: Re: Bitcoin API
Post by: LZ on March 09, 2011, 08:10:49 PM
I prefer the first option (through HTTPS or SSH) using Python.

You may just use getnewaddress "sometradeid" and getbalance "sometradeid".

And do not forget to use backupwallet "somepath" as often as possible. Ideally,
after each transaction. You may generate filenames with the current date/time.

Links to the additional information:
  • https://en.bitcoin.it/wiki/Accounts_explained (https://en.bitcoin.it/wiki/Accounts_explained)
  • https://en.bitcoin.it/wiki/API_tutorial_(JSON-RPC) (https://en.bitcoin.it/wiki/API_tutorial_(JSON-RPC))


Title: Re: Bitcoin API
Post by: jav on March 09, 2011, 08:36:18 PM
For bitcoinmonitor.com I also run bitcoind directly. I'm using a VPS from prmgr.com. Currently I'm on their 256 MiB offer - as Gavin said, the daemon doesn't need many resources.

But I think you listed pretty much all the possible options. And you are right that for your typical PHP-only webhosting the options are a little limited right now. But options 2) and 3) are probably your best bet there. For mybitcoin.com you write that you have to "install/compile/run something". I haven't used the API myself, but I looked briefly at it and I think you are overestimating the amount of "installing" involved there. It is basically just some code that goes on and does that 'constructing/posting a URL' that you mentioned. If you really wanted to, you could probably construct those HTTP requests yourself, but then you would just reimplemented what the API package already provides. So if you are saying that their API gives you everything you need, then I would suggest to have a closer look at it again.


Title: Re: Bitcoin API
Post by: dacoinminster on March 09, 2011, 08:48:41 PM
For mybitcoin.com you write that you have to "install/compile/run something". I haven't used the API myself, but I looked briefly at it and I think you are overestimating the amount of "installing" involved there. It is basically just some code that goes on and does that 'constructing/posting a URL' that you mentioned. If you really wanted to, you could probably construct those HTTP requests yourself, but then you would just reimplemented what the API package already provides. So if you are saying that their API gives you everything you need, then I would suggest to have a closer look at it again.

I took a closer look, and I have a couple more objections to the mybitcoin.com API:

1) No way to generate a new address. This is handled internally at mybitcoin.com - I just send the user there and wait for the site to do a callback.

2) No way to query if a user has paid, and how many confirmations have passed. I just have to wait for a callback.

A callback procedure does not offer me enough visibility into what is happening.


Thanks for the comments everyone. It looks like what I want doesn't exist yet, so I'll offer a small bounty: 20BTC

Payable to the first online wallet service (new or existing) who provides the world with a URL API something like this:

https://www.coolservice.com?user=dacoinminster&pwd=mypassword&action=spend&address=bitcoin_address_to_send_to&amount=#
(an equivalent one for this already exists at mtgox)

https://www.coolservice.com?user=dacoinminster&pwd=mypassword&action=getnewaddress
(returns new bitcoin address which I can give to a customer)

https://www.coolservice.com?user=dacoinminster&pwd=mypassword&action=seecoins
(returns my BTC balance)

https://www.coolservice.com?user=dacoinminster&pwd=mypassword&action=seecoins&address=bitcoin_address_of_mine
(returns number of BTC sent to that address, and number of confirmations received so far)

https://www.coolservice.com?user=dacoinminster&pwd=mypassword&action=seetransactions
(returns all my transactions ever, with addresses and # of confirmations for each one)

Bounty is only payable if the service is free to everyone. Website must be either already trusted, or must establish a trustworthy reputation. Hopefully others interested in having a service like this will add to my little bounty.

I have added the bounty information to the first post in this thread. Future updates will be there.


Title: Re: Bitcoin API
Post by: bitcoinex on March 09, 2011, 08:50:16 PM
Useful if you make site on bitcoind:

http://bitcointalk.org/index.php?topic=703.msg7709#msg7709


Title: Re: Bitcoin API - 20 BTC Bounty
Post by: error on March 09, 2011, 08:59:38 PM
Coincidentally, I am planning to implement a new online wallet service. I will be sure to add these features to it. :)


Title: Re: Bitcoin API - 20 BTC Bounty
Post by: dacoinminster on March 09, 2011, 09:03:53 PM
Coincidentally, I am planning to implement a new online wallet service. I will be sure to add these features to it. :)

Obviously things always take longer than expected, but do you have any idea how soon you will be launching?


Title: Re: Bitcoin API - 20 BTC Bounty
Post by: error on March 09, 2011, 09:17:55 PM
Coincidentally, I am planning to implement a new online wallet service. I will be sure to add these features to it. :)

Obviously things always take longer than expected, but do you have any idea how soon you will be launching?

When it's ready. ;D

Hopefully in about a week or so I'll be able to open it for public testing. There are some features it will have that don't yet exist anywhere else, and that's going to take some work. That's all I'm gonna say about such features right now...


Title: Re: Bitcoin API - 20 BTC Bounty
Post by: theymos on March 09, 2011, 09:23:19 PM
I'd just use bitcoind remotely. If you don't want to set up Bitcoin's own remote RPC ability, you could pretty easily create a PHP server that does what you want using GET parameters.

MyBitcoin is used on a lot of sites. I like the customer-side experience, though I've never used it on the server side.


Title: Re: Bitcoin API - 20 BTC Bounty
Post by: dacoinminster on March 09, 2011, 09:59:31 PM
I have an interesting social experiment I'm going to run, to try to turn my 20BTC pledge into a 200 BTC pledge:

If you are a trusted forum member, and you would like to see this feature happen, pledge on this thread. I will send you 1/10 of your pledge amount right now, (deducting it from my original pledge). This offer is subject to my deciding if you seem honest, trusted on this forum, and serious about your pledge.


Title: Re: Bitcoin API - 20 BTC Bounty
Post by: LZ on March 10, 2011, 01:38:06 AM
I do not think that it is a good idea. It is better to let someone do something, then you will pay.

Added. On the other hand, gavin or themos can make that web site in an hour or even faster...


Title: Re: Bitcoin API - 20 BTC Bounty
Post by: dacoinminster on March 30, 2011, 01:04:59 AM
I added this bounty to the list of active bounties: https://en.bitcoin.it/wiki/Active_Bounties


Title: Re: Bitcoin API - 20 BTC Bounty
Post by: genjix on March 30, 2011, 05:56:43 AM
I wrote https://en.bitcoin.it/wiki/PHP_developer_intro


Title: Re: Bitcoin API - 20 BTC Bounty
Post by: Alex Beckenham on March 30, 2011, 01:42:58 PM
I wrote https://en.bitcoin.it/wiki/PHP_developer_intro

Embarrassingly dumb question:

If using localhost, there's no risk of password-sniffing on http?
http://user:password@127.0.0.1:8332/
That kind of traffic never even leaves your box, correct?


Title: Re: Bitcoin API - 20 BTC Bounty
Post by: dacoinminster on April 01, 2011, 03:58:47 PM
I added this bounty to the list of active bounties: https://en.bitcoin.it/wiki/Active_Bounties

I solved my problem, and I am hereby paying the bounty to myself the bounty has been paid to blockexplorer.com!

Problem:
Lazy web designer (me) wants to use bitcoins without dealing with installing bitcoin on a server, installing a shopping cart interface, or using ugly merchant services with callbacks.

Solution for sending bitcoins:
Use the MtGox API (https://mtgox.com/support/tradeAPI)

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.

Bad idea:
Selling bars of gold this way (owner of blockexplorer.com could rip you off)

Good(?) idea:
Selling naked pictures of your grandma this way (owner of blockexplorer.com won't bother)

Shameless begging:
If this info is useful to you, please consider a donation: 19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH

Maybe I'm the only one this lazy, but just in case, I added a page to the wiki: https://en.bitcoin.it/wiki/Lazy_API

Thanks to theymos for making changes to blockexplorer.com to make it even easier to do this. Because of those changes to better support what I want to do, I paid Theymos the 20BTC bounty. You can support blockexplorer.com too by donating to 1Cvvr8AsCfbbVQ2xoWiFD1Gb2VRbGsEf28


Title: Re: Bitcoin API - solved!
Post by: theymos on April 02, 2011, 05:16:02 AM
I modified the wiki page to use BBE's API pages:
http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH
http://blockexplorer.com/q/getblockcount

You shouldn't scrape the HTML pages. The layout can change at any time.


Title: Re: Bitcoin API - solved!
Post by: dacoinminster on April 03, 2011, 08:57:19 PM
I modified the wiki page to use BBE's API pages:
http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH
http://blockexplorer.com/q/getblockcount

You shouldn't scrape the HTML pages. The layout can change at any time.

Nice! That will be much easier. I updated my post above as well.

I found the complete API description here: http://blockexplorer.com/q/

It would be nice if the front page of blockexplorer.com linked to that page.


Title: Re: Bitcoin API - solved!
Post by: Hal on April 04, 2011, 03:21:19 AM
I added a step to the wiki:

# Recheck blockexplorer to make sure the address still shows the right amount, in case the block chain reorganizes

Checking the address balance once, then waiting for more blocks, is not safe by itself as the transaction may go away.

(Just realized my solution is still vulnerable: the transaction could pay you, go away, you wait n blocks, and a different transaction pays you, you recheck the balance and it looks good, but then the 2nd transaction goes away.)


Title: Re: Bitcoin API - solved!
Post by: theymos on April 04, 2011, 04:39:03 AM
(Just realized my solution is still vulnerable: the transaction could pay you, go away, you wait n blocks, and a different transaction pays you, you recheck the balance and it looks good, but then the 2nd transaction goes away.)

Yeah, /q/getreceivedbyaddress is currently only suitable when you need just 1 confirmation. I'll add a "minconf" parameter when I get time.


Title: Re: Bitcoin API - solved!
Post by: theymos on April 04, 2011, 05:06:05 AM
It wasn't as hard as I thought it would be, so I added it now.

6 confirmations:
http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH/6
1,000,000 confirmations:
http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH/1000000


Title: Re: Bitcoin API - solved!
Post by: dacoinminster on April 04, 2011, 04:06:20 PM
It wasn't as hard as I thought it would be, so I added it now.

6 confirmations:
http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH/6
1,000,000 confirmations:
http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH/1000000

That is absolutely perfect. I updated my forum post and the wiki to reflect this method. I even put your blockexplorer.com donation address at the bottom  :P

Since theymos made changes to support what I want to do, I paid the 20BTC bounty using the donation address for blockexplorer.com

Theymos, please support laziness by adding a link to the API description from the blockexplorer.com home page. Thanks!


Title: Re: Bitcoin API - solved!
Post by: theymos on April 04, 2011, 08:16:59 PM
Since theymos made changes to support what I want to do, I paid the 20BTC bounty using the donation address for blockexplorer.com

Theymos, please support laziness by adding a link to the API description from the blockexplorer.com home page. Thanks!

Thanks for the 20 BTC! I added a link.


Title: Re: Bitcoin API - solved!
Post by: frenkel on May 23, 2011, 06:13:55 PM
It wasn't as hard as I thought it would be, so I added it now.

6 confirmations:
http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH/6
1,000,000 confirmations:
http://blockexplorer.com/q/getreceivedbyaddress/19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH/1000000

Hi theymos,

Your examples give me an error, it doesn't seem to work anymore:
Quote
ERROR: this page never counts 0-confirmation transactions


Title: Re: Bitcoin API - solved!
Post by: theymos on May 23, 2011, 07:41:32 PM
Fixed. Thanks.


Title: Re: Bitcoin API - solved!
Post by: frenkel on May 23, 2011, 07:48:09 PM
Cool, thanks!


Title: Re: Bitcoin API - solved!
Post by: andrehorta on April 08, 2013, 10:35:43 PM
How can i create a new address?


Title: Re: Bitcoin API - solved!
Post by: Amitabh S on August 05, 2013, 07:31:10 PM
How can i create a new address?

A tool (that claims to run on client side - have not verified) is bitaddress (http://bitaddress.org), which lets you generate random addresses.


Title: Re: Bitcoin API - solved!
Post by: Judson on August 06, 2013, 03:37:42 AM
This thread is 2 years old.


Title: Re: Bitcoin API
Post by: jlp on February 08, 2014, 03:07:52 AM
1) bitcoind - I think this might be the same as configuring bitcoin to run as server. I believe it uses an RPC API to run transactions from the command line.
Pros: Everything stays on my server
Cons: I have to find a server that will let me compile and install this, rather than just some PHP/MySQL farm in the cloud, which is what I prefer

You can run the front-end on one server and the back-end on another (and communicate via JSON-RPC over HTTPS).  That's how I'm able to run the Faucet and ClearCoin on Google's App Engine (they talk with bitcoind processes running on linode.com and aws.amazon.com servers).  bitcoind doesn't take much memory, bandwidth, or CPU (just don't turn on coin generation), so, for now, anyway, you can even use an Amazon "micro" server (which costs something like $100 per year).

I'm not selling anything so can't comment on the shopping cart interfaces.  Screen-scraping web pages is a bad idea for lots of reasons.


What is the speed/performance like if one runs the web app and bitcoind on two separate remote servers?  Won't the speed be slow?

The JSON-RPC in the web app sends the user name and password to access the bitcoind API.  Do both the web app's server and the bitcoind server need HTTPS, or just the bitcoind server is sufficient?

Which hosting company is best for this type of architecture?  Google App Engine, AWS EC2, DigitalOcean or Linode?

What about security?  Do I need to encrypt the wallet on the server?  How do I ensure that nobody at the hosting company accesses my server, reads the rpcuser and rpcpassword in bitcoin.conf and then starting sending Bitcoins out of my wallet?  If I move away, how do I ensure that the hosting company or the next customer doesn't take a copy of my wallet?


Title: Re: Bitcoin API - solved!
Post by: nasamanBoy on February 08, 2014, 08:03:32 AM
Here you have one interesting page  http://176.221.46.81/chain/Quarkcoin....


Title: Re: Bitcoin API - solved!
Post by: thonglor on March 02, 2014, 07:47:35 AM
Now as MtGox has gone down, is there another API/webpage that can be recommended?


Title: Re: Bitcoin API - solved!
Post by: grifferz on March 02, 2014, 08:46:17 AM
Now as MtGox has gone down, is there another API/webpage that can be recommended?
What features do you require?

I do not use it myself but I have heard good things about blockchain.info's API.


Title: Re: Bitcoin API - solved!
Post by: thonglor on March 02, 2014, 11:01:22 AM
Yes, I'm trying to do exactly that but experience this error on testing their API:

https://bitcointalk.org/index.php?topic=495631.0


Title: Re: Bitcoin API - 20 BTC Bounty
Post by: OWZ1337 on June 09, 2018, 09:09:51 PM
I added this bounty to the list of active bounties: https://en.bitcoin.it/wiki/Active_Bounties

I solved my problem, and I am hereby paying the bounty to myself the bounty has been paid to blockexplorer.com!

Problem:
Lazy web designer (me) wants to use bitcoins without dealing with installing bitcoin on a server, installing a shopping cart interface, or using ugly merchant services with callbacks.

Solution for sending bitcoins:
Use the MtGox API (https://mtgox.com/support/tradeAPI)

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.

Bad idea:
Selling bars of gold this way (owner of blockexplorer.com could rip you off)

Good(?) idea:
Selling naked pictures of your grandma this way (owner of blockexplorer.com won't bother)

Shameless begging:
If this info is useful to you, please consider a donation: 19hMEAaRMbEhfSkeU4GT8mgSuyR4t4M6TH

Maybe I'm the only one this lazy, but just in case, I added a page to the wiki: https://en.bitcoin.it/wiki/Lazy_API

Thanks to theymos for making changes to blockexplorer.com to make it even easier to do this. Because of those changes to better support what I want to do, I paid Theymos the 20BTC bounty. You can support blockexplorer.com too by donating to 1Cvvr8AsCfbbVQ2xoWiFD1Gb2VRbGsEf28

this sounds too like wayyyy too much effort! :) haha

===>

https://en.bitcoin.it/wiki/Lazy_API


Title: Re: Bitcoin API - solved!
Post by: Jonbak on June 11, 2018, 09:57:22 PM
BlockCypher API! BlockCypher is a simple JSON API, mostly RESTful for using blockchain, accessible via HTTP or HTTPS from the api.blockcypher.com domain. Currently, BlockCypher supports Bitcoin, Ethereum, Litecoin, Dogecoin, Bitcoin Testnet3, and BlockCypher Test Chain.
BlockCypher's API provides a superset of the endpoints you'll find in reference implementations, in addition to some special features that make BlockCypher uniquely powerful, such as Unconfirmed Confidence Factor, WebHook Event or Web-based WebSockets Reliable, On-Chain Micro Transactions, and Payment Forward.

As a result, if you are familiar with the implementation of blockchain referrals, you will feel at home using BlockCypher, but without worrying about scale or implementation challenges. And if you're not familiar - with the application of referrals or blockchain in general - BlockCypher's API is a great way to dip your toes into the development of blockchain, without a lengthy regulatory process. In any case, BlockCypher has 99.99% time-active, and maintains the expressive and logical API you'll like.