Be a Supporter!

Bitcoin micro transactions

  • 588 Views
  • 19 Replies
New Topic Respond to this Topic
AnteHero
AnteHero
  • Member since: Sep. 5, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Bitcoin micro transactions 2013-11-15 16:31:20 Reply

For those of you who haven't heard of it, Bitcoin is a peer-to-peer digital currency sporting many advantages over traditional centrally issued currency. Namely, it is finite like gold, and cannot be inflated into oblivion. In the worst of times that means your wealth stored in Bitcoin is worth the same as it was yesterday and is not subject to the whims of bankers and bureaucrats. It is also international and does not require silly fees to send and receive across the world. In fact it doesn't require a bank account at all, it is stored on your computer, server, USB stick etc. And it is divisible to 8 decimal places making it ideal for micro transactions.

Bitcoins have come a long way from mere gambling and are now being accepted as payment for advertising, web hosting and hardware. While it may be some time before you can buy your groceries with them there are already Bitcoin ATMs to exchange to local currency on the high street.

There are a number of 3rd party services for sending and receiving Bitcoins from online services using php but I haven't yet seen any in AS3. Would anyone be interested in developing an AS3 API to integrate Bitcoin payments with one of these 3rd party services such as Coinbase.com?

I've been tinkering around with their API myself but I don't have much experience with php or URLLoaders for that matter.

kkots
kkots
  • Member since: Apr. 16, 2013
  • Offline.
Forum Stats
Supporter
Level 10
Blank Slate
Response to Bitcoin micro transactions 2013-11-15 17:26:27 Reply

This is outrageously illegal.
Only Bitcoin company itself is allowed to make APIs for itself, not just random people.


BBS Signature
MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to Bitcoin micro transactions 2013-11-15 17:57:26 Reply

At 11/15/13 05:26 PM, kkots wrote: This is outrageously illegal.
Only Bitcoin company itself is allowed to make APIs for itself, not just random people.

They made the server-side api, but you can communicate with that however you'd like.

At 11/15/13 04:31 PM, AnteHero wrote: I've been tinkering around with their API myself but I don't have much experience with php or URLLoaders for that matter.

I don't understand any of this stuff, but as3rpclib should be pretty much the same as the java example that's on their website. In addition, there's http authentication here.

AnteHero
AnteHero
  • Member since: Sep. 5, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Bitcoin micro transactions 2013-11-15 18:06:28 Reply

At 11/15/13 05:26 PM, kkots wrote: This is outrageously illegal.
Only Bitcoin company itself is allowed to make APIs for itself, not just random people.

lol, it's neither illegal nor outrageous.
Bitcoin is open source and there are many 3rd party wallets which access the Bitcoin network.
If Bitcoin was so flimsy that it relied on the law to make it secure then it wouldn't be used at all.
And I'm not talking about an API for a Bitcoin wallet I'm talking about an AS3 library to streamline communication between your app, your servers and the coinbase API.
Coinbase is a 3rd party service which has it's own Bitcoin wallets on it's servers, it's a bit like Paypal.
You can go create an account there without having to install your own Bitcoin wallet.
They have an extensive API for communicating with your account and will send invoices to your users email address, notify you of payments, ping your servers etc.
So I'm sure they would be delighted to see people extending their interface.

AnteHero
AnteHero
  • Member since: Sep. 5, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Bitcoin micro transactions 2013-11-15 18:35:07 Reply

I don't understand any of this stuff, but as3rpclib should be pretty much the same as the java example that's on their website. In addition, there's http authentication here.

Yeah I don't understand as3rpclib either. Does it just make JSON requests a bit easier.

That second link is all server side stuff right?
I'm sure you can send coinbase a JSON object and a callback URL to send it to when your transaction is complete so I don't think any server side stuff is required.

AnteHero
AnteHero
  • Member since: Sep. 5, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Bitcoin micro transactions 2013-11-15 19:57:03 Reply

At 11/15/13 05:26 PM, kkots wrote: This is outrageously illegal.
Only Bitcoin company itself is allowed to make APIs for itself, not just random people.

Here we are.
"We plan on adding more client libraries in the future. If you develop a client library that you'd like to open source and add to this page, please send us a note. We'll be happy to give you attribution."

AnteHero
AnteHero
  • Member since: Sep. 5, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Bitcoin micro transactions 2013-11-15 21:41:35 Reply

I'm having trouble passing JSON objects

private function requestMake():void {

    var json:Object = {
        transaction: {
            from: "myAddress@example.com",
            amount: "0.15"
        }
    };

    var request:URLRequest = new URLRequest( baseURL + requestMoney + apiKey );
    request.method = URLRequestMethod.POST;
    request.data = new URLVariables();
    request.data.data = JSON.stringify( json );

    var loader:URLLoader = new URLLoader();
    loader.addEventListener("complete", complete);
    loader.load( request );
}

private function complete(e:Event):void {

    var loader:URLLoader = e.target as URLLoader;
    var result:Object = JSON.parse( loader.data );
    for (var str:String in result) {
        trace( str+" "+result[str] );
    }
}

The other commands which don't require JSON objects run just fine and return JSON objects with the desired result however this one returns an error message saying invalid or no email address when I'm using my coinbase registered address.

You'll need an account and API key to test it yourself but I haven't a clue what's causing this, I'm getting an invalid address error when it's definitely not.

MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to Bitcoin micro transactions 2013-11-15 22:34:27 Reply

At 11/15/13 09:41 PM, AnteHero wrote: You'll need an account and API key to test it yourself but I haven't a clue what's causing this, I'm getting an invalid address error when it's definitely not.

If there's an actual problem, you could probably shoot them an email. Just make sure you aren't doing something dumb like forgetting to set a variable. I thought you had to use the http authenticator thing here to establish a secure connection, but then again, I have no idea what I read on that page.

AnteHero
AnteHero
  • Member since: Sep. 5, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Bitcoin micro transactions 2013-11-16 14:05:43 Reply

At 11/15/13 10:34 PM, MSGhero wrote:
At 11/15/13 09:41 PM, AnteHero wrote: You'll need an account and API key to test it yourself but I haven't a clue what's causing this, I'm getting an invalid address error when it's definitely not.
If there's an actual problem, you could probably shoot them an email. Just make sure you aren't doing something dumb like forgetting to set a variable. I thought you had to use the http authenticator thing here to establish a secure connection, but then again, I have no idea what I read on that page.

I probably am doing something dumb, which is why I need a fresh pair of eyes to look at my code :p
Here is the reference for the request money method.
The required parameters, transaction, from, and amount are included in the JSON object. However, the invalid email error is returned.

I'm just using the API key to access my own account for now, I will use the OAuth2 method when I'm more familiar with the API, unless you think that's the problem?
Will I have to dig into the SecureSocket class to get that working?
Like I said, I'm a total noob with this stuff so any help is appreciated.

MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to Bitcoin micro transactions 2013-11-16 14:16:12 Reply

At 11/16/13 02:05 PM, AnteHero wrote: I probably am doing something dumb, which is why I need a fresh pair of eyes to look at my code :p
Like I said, I'm a total noob with this stuff so any help is appreciated.

I know less about it than you do at this point. Go to your account settings page or whatever and copy paste the registered email into your file. Trace your stringified json to see if it looks like it's supposed to. Stringify takes 2 parameters, so be sure you don't need the 2nd one.

When coinbase gives you the error, how does it show up? Is e.success false? Does the json it returns have some kind of error message in it?

AnteHero
AnteHero
  • Member since: Sep. 5, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Bitcoin micro transactions 2013-11-16 14:32:16 Reply

At 11/16/13 02:16 PM, MSGhero wrote: I know less about it than you do at this point. Go to your account settings page or whatever and copy paste the registered email into your file. Trace your stringified json to see if it looks like it's supposed to. Stringify takes 2 parameters, so be sure you don't need the 2nd one.

Stringified JSON traces this:

{"transaction":{"amount":"0.15","from":"myAddress@example.com"}}

The reference says the from field must be a string so I don't think I need the replacer argument in stringify.

When coinbase gives you the error, how does it show up? Is e.success false? Does the json it returns have some kind of error message in it?

The event is just fine, no errors there, but the JSON object contains the error:

success: false
errors: Please enter an email address in the from field.
transaction: [object Object]

The transaction object just has a bunch of null parameters in it, just as the documentation says it would.

AnteHero
AnteHero
  • Member since: Sep. 5, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Bitcoin micro transactions 2013-11-16 14:43:53 Reply

And yes I am using my own email address, not 'myAddress@example.com'

AnteHero
AnteHero
  • Member since: Sep. 5, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Bitcoin micro transactions 2013-11-16 14:49:11 Reply

Here is the returned JSON in full

{
    "success":false,
    "errors":["Please enter an email address in the from field."],
    "transaction":
    {
        "id":"5287cb62cec0c40a3300041c",
        "created_at":null,
        "hsh":null,
        "amount":
        {
            "amount":"0.00000000",
            "currency":"BTC"
        },
    "request":false,
    "status":"pending",
    "notes":""
    }
}
MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to Bitcoin micro transactions 2013-11-16 14:58:22 Reply

At 11/16/13 02:32 PM, AnteHero wrote: Stringified JSON traces this:

{"transaction":{"amount":"0.15","from":"myAddress@example.com"}}

This is when I would start monkeying around. Try doing a GET on your transaction history. If that doesn't work, you need oath2. Try tracing the UrlVariables thing. From scanning the docs, I feel like that object should have the transaction,amount,notes properties, not a data property with all that included.

AnteHero
AnteHero
  • Member since: Sep. 5, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Bitcoin micro transactions 2013-11-17 13:35:37 Reply

At 11/16/13 02:58 PM, MSGhero wrote: This is when I would start monkeying around. Try doing a GET on your transaction history. If that doesn't work, you need oath2. Try tracing the UrlVariables thing. From scanning the docs, I feel like that object should have the transaction,amount,notes properties, not a data property with all that included.

Yeah, GET transactions works fine, it must be a problem with sending the JSON.
I think the problem is with the key string I'm using to represent the JSON.
Changed 'data' to 'request':

var request:URLRequest = new URLRequest( baseURL + requestMoney + apiKey );
request.method = URLRequestMethod.POST;
request.data = new URLVariables( "request="+JSON.stringify(json) );

Which returns the same error, I don't actually know what the key should be, I can't find it in the documentation.
Also tried setting data to the JSON instead of a URLVariables object:

var request:URLRequest = new URLRequest( baseURL + requestMoney + apiKey );
request.method = URLRequestMethod.POST;
request.data = JSON.stringify(json);

Again, it's the same error.
But sending an empty variables object returns that same error:

var request:URLRequest = new URLRequest( baseURL + requestMoney + apiKey );
request.method = URLRequestMethod.POST;
request.data = new URLVariables( "data= " );

Which means that is the default error message and probably does not give any clues as to the actual problem right?

MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to Bitcoin micro transactions 2013-11-17 13:46:51 Reply

At 11/17/13 01:35 PM, AnteHero wrote: Which means that is the default error message and probably does not give any clues as to the actual problem right?

Just do

uv = new URLVariables();
uv.transaction = {amount:.15, from:email}

That seems like what urlvars is supposed to be used for according to the docs.

AnteHero
AnteHero
  • Member since: Sep. 5, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Bitcoin micro transactions 2013-11-17 14:03:12 Reply

At 11/17/13 01:46 PM, MSGhero wrote: Just do

uv = new URLVariables();
uv.transaction = {amount:.15, from:email}

That seems like what urlvars is supposed to be used for according to the docs.

Nah that gets me a flash error:

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error.
AnteHero
AnteHero
  • Member since: Sep. 5, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Bitcoin micro transactions 2013-11-17 16:51:11 Reply

Problem solved:

var json:Object = {
    transaction: {
        from: "someAddress@example.com",
        amount: "0.15"
    }
};

var request:URLRequest = new URLRequest( baseURL + requestMoney + apiKey );
request.method = URLRequestMethod.POST;
request.data = JSON.stringify(json);
request.requestHeaders.push(new URLRequestHeader("Content-type", "application/json"));

var loader:URLLoader = new URLLoader();
loader.addEventListener("complete", complete);
loader.load( request );

Don't bother with URLVariables, set request.data to the JSON string and set content type to application/json.
I then got the error: 'cannot send invoice to your own account'.
So I used a friends address and got a success message.

cindyEvans
cindyEvans
  • Member since: Dec. 19, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Bitcoin micro transactions 2014-01-08 02:31:44 Reply

The crazy ride of bitcoin is unbelievable. Amidst the speculations (China crushing it, FBI seizing the black market, Thailand banning, etc.) it remains a stumbling block that any currency should be fear of.

epicaldude
epicaldude
  • Member since: Aug. 5, 2013
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to Bitcoin micro transactions 2014-02-23 19:25:55 Reply

At 11/15/13 05:26 PM, kkots wrote: This is outrageously illegal.
Only Bitcoin company itself is allowed to make APIs for itself, not just random people.

Rotfl.

There is no "bitcoin company", it's like saying emails can be only sent be "the email company" and mathematics can be used only by "the math company".

Bitcoin is an open protocol, virtual currency that everyone in the world can create, trade in, write programs for, and no one can print it out of thin air (to inflate it).