Bitcoin Forum
April 24, 2024, 05:12:26 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [ANN] API for Instawallet  (Read 2163 times)
jav (OP)
Sr. Member
****
Offline Offline

Activity: 249
Merit: 251


View Profile
July 07, 2011, 11:30:23 PM
Last edit: July 11, 2011, 04:17:37 PM by jav
 #1

I'm happy to announce that there is now an API available for Instawallet. This API can be used to write mobile clients, desktop clients, browser plugins or any other cool stuff you can come up with. There already exists one Android client that uses Instawallet (BitPay), which currently screen-scrapes the Instawallet site, but plans to switch to this API soon.

I will put up the complete documentation on the Instawallet site soon. To see the API in action, I wrote a simple console client for Linux that can be found on GitHub: https://github.com/javgh/iw-console/blob/master/iw-console.py . Screenshot:



Here is a quick overview of the API. All calls return JSON-encoded data:

HTTP POST https://www.instawallet.org/api/v1/new_wallet
    Creates a new Instawallet.
    Example response: {"successful": true, "wallet_id": "1CKAK7zU5NGUlY1n3PK0aw"}
    Note: You can also use HTTP GET, but this is deprecated.

HTTP GET https://www.instawallet.org/api/v1/w/<wallet_id>/address
    Returns the Bitcoin address associated with this Instawallet.
    Example response: {"successful": true, "address": "1PmggT9YKj4HL2iaUs8ukUSvvk3Q1xMv5G"}

HTTP GET https://www.instawallet.org/api/v1/w/<wallet_id>/balance
    Returns the current balance in Bitcoin base units (Satoshis). This means 0.01 BTC will be returned as 1000000.
    Example response: {"successful": true, "balance": 1000000}

HTTP POST https://www.instawallet.org/api/v1/w/<wallet_id>/payment
    Your request needs to include the parameters "address" and "amount". Amount should be in Bitcoin base units (Satoshis). Example response: {"successful": true, "message": "Sent 0.01 BTC to 14Z1mazY4HfysZyMaKudFr63EwHqQT2njz", "message_code": 0}

If an error occurred or the API is not available for some reason, the parameter "succesful" will be false and a "message" as well as a "message_code" will be returned alongside. See the following table for possible messages and codes:
1   The API is currently unavailable.
2   Please provide a Bitcoin address.
3   Please specify the amount you would like to send.
4   Sorry, this does not look like a valid Bitcoin address.
5   Sorry, I was not able to parse the amount field.
6   Sorry, currently only amounts of 0.01 BTC and more are supported.
-4   Sorry, this does not seem to be a valid Bitcoin address
-6   Account has insufficient funds (or not enough confirmations) to complete this action
0   Sent <amount> BTC to <address>

The API also provides a way to get push-notifications on balance change. To use this feature, you first need to get a subscription ID:

HTTP POST https://www.instawallet.org/api/v1/w/<wallet_id>/subscription
    Returns a subscription ID to be used with the push-notification service.
    Example response: {"successful": true, "subscription_id": 1563757213}

The next step is to open a standard socket connection to www.instawallet.org:8202 and to send a JSON object encoding the subscription ID on a single line (terminated by either "\n" or "\r\n") like this: {"subscription_id": 1563757213} . Only the first such object will be accepted, further lines will be ignored. The server should respond with a "ping" (regardless of whether the subscription ID is valid or not). You now simply keep the connection open and the server will send another "ping" each time the balance on the server changes. Note: Because of the subscription mechanism the socket connection can be unencrypted.

Feedback and comments welcome!

Hive, a beautiful wallet with an app platform for Mac OS X, Android and Mobile Web. Translators wanted! iOS and OS X devs see BitcoinKit. Tweets @hivewallet. Donations appreciated at 1HLRg9C1GsfEVH555hgcjzDeas14jen2Cn.
1713935546
Hero Member
*
Offline Offline

Posts: 1713935546

View Profile Personal Message (Offline)

Ignore
1713935546
Reply with quote  #2

1713935546
Report to moderator
1713935546
Hero Member
*
Offline Offline

Posts: 1713935546

View Profile Personal Message (Offline)

Ignore
1713935546
Reply with quote  #2

1713935546
Report to moderator
There are several different types of Bitcoin clients. The most secure are full nodes like Bitcoin Core, which will follow the rules of the network no matter what miners do. Even if every miner decided to create 1000 bitcoins per block, full nodes would stick to the rules and reject those blocks.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713935546
Hero Member
*
Offline Offline

Posts: 1713935546

View Profile Personal Message (Offline)

Ignore
1713935546
Reply with quote  #2

1713935546
Report to moderator
semarjt
Newbie
*
Offline Offline

Activity: 27
Merit: 0


View Profile
July 08, 2011, 05:31:14 AM
 #2

just out of curiosity, why GET /new_wallet, when the other calls all seem more RESTful

GET should be idempotent
bogeyman
Newbie
*
Offline Offline

Activity: 8
Merit: 0


View Profile
July 08, 2011, 06:21:32 AM
 #3

Hooray for the API! I'll think now I have to code something...  Grin
jav (OP)
Sr. Member
****
Offline Offline

Activity: 249
Merit: 251


View Profile
July 08, 2011, 08:48:26 AM
 #4

just out of curiosity, why GET /new_wallet, when the other calls all seem more RESTful

GET should be idempotent

Hey! Thx for the feedback. I was indeed a little bit torn between a GET and a POST for this call and this is my first attempt at a RESTful service so I welcome input. I guess my reasoning here is, that this doesn't actually change anything on the server. Since Instawallets are just random links, they are not really "created".

So in that light, if you had a call to /api/random_number would you make it a GET or a POST? (honest question).

And a question about "idempotency": I agree with the general concept, but wonder about situations like this: Let's say you have a /api/current_time call. I would model that as a HTTP GET, even though it doesn't seem idempotent to me - two calls will return different times. Or is it idempotent in the sense, that theoretically the calls could return the same data if you would execute them fast enough?

Hive, a beautiful wallet with an app platform for Mac OS X, Android and Mobile Web. Translators wanted! iOS and OS X devs see BitcoinKit. Tweets @hivewallet. Donations appreciated at 1HLRg9C1GsfEVH555hgcjzDeas14jen2Cn.
dserrano5
Legendary
*
Offline Offline

Activity: 1974
Merit: 1029



View Profile
July 08, 2011, 09:18:28 AM
 #5

Any chance to have firstbits (currently down due to a bug hunt) integrated? Whenever a given address is shorter than N characters (I think firstbits uses 22 but can't remember right now), a query to the firstbits API is made to discover the full address, and the process continues from that point on.

Thus, we could do: payment 12345 0.01. Sweet, isn't it?
mndrix
Michael Hendricks
VIP
Sr. Member
*
Offline Offline

Activity: 447
Merit: 258


View Profile
July 08, 2011, 04:23:13 PM
 #6

Thank you.  I hoped you would do this.  I have an interesting project idea that would benefit from this API. Is the API mentioned on your site anywhere?  I didn't see a link.
bitlotto
Hero Member
*****
Offline Offline

Activity: 672
Merit: 500


BitLotto - best odds + best payouts + cheat-proof


View Profile WWW
July 08, 2011, 04:58:25 PM
 #7

Pretty cool! This will enable a lot of small portable bitcoin related apps! Thank you!

*Next Draw Feb 1*  BitLotto: monthly raffle (0.25 BTC per ticket) Completely transparent and impossible to manipulate who wins. TOR
TOR2WEB
Donations to: 1JQdiQsjhV2uJ4Y8HFtdqteJsZhv835a8J are appreciated.
jav (OP)
Sr. Member
****
Offline Offline

Activity: 249
Merit: 251


View Profile
July 08, 2011, 09:08:27 PM
 #8

Any chance to have firstbits (currently down due to a bug hunt) integrated?

Hey! I think Firstbits is a really cool idea (especially since it only relies on the block chain)  and have been toying with the idea of integrating it into Instawallet. If I do, I will probably implement the algorithm myself, as to not be dependent on external services.

However, there is one thing I find a little worrying: It encourages reuse of Bitcoin addresses, since it can't work otherwise. I don't really want that catching on, especially among merchants, because I think the "proper" way of doing a sale with Bitcoin is to use a fresh address. So for that reason, I have put Firstbit support on the back burner for now. But I'll keep it in mind. Great project nevertheless!

Thank you.  I hoped you would do this.  I have an interesting project idea that would benefit from this API. Is the API mentioned on your site anywhere?  I didn't see a link.

It's not on the site yet, no. This thread is pretty much all the documentation there is. Hopefully I find some time in the next days to move it to the website. PS: I'll be looking forward to your project, I think you did a great job with Coinpal! :-)

Hive, a beautiful wallet with an app platform for Mac OS X, Android and Mobile Web. Translators wanted! iOS and OS X devs see BitcoinKit. Tweets @hivewallet. Donations appreciated at 1HLRg9C1GsfEVH555hgcjzDeas14jen2Cn.
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!