Skip to content

Instantly share code, notes, and snippets.

@charleyhine
charleyhine / gist:5457d2d3a36b17f7f820
Created February 9, 2015 18:50
Receive Chain.com Notification (Address)
def result
tx = JSON.parse(request.raw_post)
type = tx['payload']['type']
confs = tx['payload']['confirmations']
amount_s = tx['payload']['received']
tx_id = tx['payload']['transaction_hash']
addr = tx['payload']['address']
render nothing: true, status: 200
end
<!DOCTYPE html>
<html>
<head>
<title>Bitcoin API - Chain</title>
<link rel='shortcut icon' type='image/x-icon' href='/chain32x32.ico' />
<link rel='shortcut icon' type='image/x-icon' href='/chain16x16.ico' />
<meta name="description" content="Chain is a powerful block chain API that makes it easy to build Bitcoin applications.">
<!--facebook meta tags-->
@charleyhine
charleyhine / gist:04f8374966fa1985df4e
Last active August 29, 2015 14:06
Create Payment Address (URL argument)

Create Payment Address (revised)

Create with new URL (POST)

https://api.chain.com/v1/payments

{
    "block_chain": "bitcoin",
    "destination_address": "1dk2l...",
    "webhook_url": "http://coinsafe.com/chain/random_id_here/",
Verifying that +charley is my Bitcoin username. You can send me #bitcoin here: https://onename.io/charley
@charleyhine
charleyhine / gist:2197b76ed8f276f2dadc
Created August 1, 2014 00:33
Chain webhooks URL -> Ruby response
class HomeController < ApplicationController
def callback
puts request.body.read
respond_to do |format|
format.all { render text: request.body.read }
end
end
end
@charleyhine
charleyhine / gist:abf228e3b9e680cbcb46
Created July 31, 2014 23:44
Chain webhooks -> Ruby
class HomeController < ApplicationController
skip_before_filter :verify_authenticity_token, only: [:callback]
def register_callback
register_url = 'https://api.chain.com/v1/webhooks?key=GUEST-TOKEN'
callback_url = 'http://chain-hooks.herokuapp.com/callback'
callback_alias = 'charley'
response = HTTParty.post(register_url,
body: { url: callback_url,
@charleyhine
charleyhine / gist:4e7b227d8fe2977f507a
Last active August 29, 2015 14:04
Get Address :: "unconfirmed_balance"
{
"hash": "1Bj5UVzWQ84iBCUiy5eQ1NEfWfJ4a3yKG1",
"balance": 31330001,
"received": 1032680001,
"sent": 1001350000,
"unconfirmed_received": 13600000,
"unconfirmed_sent": 13630000,
"unconfirmed_balance": -30000
}
require 'chain'
response = Chain.get_transaction_op_return('8bae12b5f4c088d940733dcd1455efc6a3a69cf9340e17a981286d3778615684')
p response['text']
=> "charley loves heidi"
@charleyhine
charleyhine / gist:0dd1a7504c00b121de74
Created June 19, 2014 23:05
Chain | Address Transactions (Ruby)
require 'uri'
require 'net/http'
# Request: My API (http://api.chain.com/v1/bitcoin/addresses/1CbC9CrmxoZAzHu16ccQsBGMNZbCZ3xAUc/transactions?limit=50)
uri = URI.parse("http://api.chain.com/v1/bitcoin/addresses/1CbC9CrmxoZAzHu16ccQsBGMNZbCZ3xAUc/transactions?limit=50")
http = Net::HTTP.new(uri.host, uri.port)
http.read_timeout = 30
request = Net::HTTP::Get.new(uri.request_uri)
### Keybase proof
I hereby claim:
* I am charleyhine on github.
* I am charley (https://keybase.io/charley) on keybase.
* I have a public key whose fingerprint is BB73 60F9 53BB D92E 48F9 AFEA 03E8 8F10 5CCC FCB4
To claim this, I am signing this object: