Skip to content

Instantly share code, notes, and snippets.

View t.txt
+------------------+ +-------------------+
| SDK/Your Process | | Chain API |
+------------------+ +-------------------+
build transaction
+------------------------------------->
transaction template
<-------------------------------------+
@ryandotsmith
ryandotsmith / transaction-template.json
Last active Aug 29, 2015
Chain.com Transaction Template -
View transaction-template.json
{
"inputs": [{
"address": "mxLGQRD9p3MayF7WrUJsyuY4cZdPSH2yA4",
"signatures_required": 1,
"signatures": [{
"address": "mxLGQRD9p3MayF7WrUJsyuY4cZdPSH2yA4",
"public_key": "<insert public key>",
"hash_to_sign": "ac366bdd3eb0ecd64d3d08a7d519d7fe5ceb263a499b135e3158fea04c87a89c",
"signature": "<insert signature>"
}]
@ryandotsmith
ryandotsmith / transact-example.js
Last active Aug 29, 2015
Chain.com Transaction - Create Bitcoin Transactions in Node.js
View transact-example.js
var Chain = require('chain-node');
var chain = new Chain(blockChain: 'testnet3');
var req = {
inputs: [{
address: "mxLGQRD9p3MayF7WrUJsyuY4cZdPSH2yA4",
// Private key never leaves this process!
private_key: "cNX5yYSnj6Bd3BEjsfV6ZQyn8hQYYDQB79vjHNkv7NAPazo9GBJT",
}],
outputs: [{
@ryandotsmith
ryandotsmith / op-return.js
Created Dec 8, 2014
Creating op-return transactions
View op-return.js
var util = require('util');
var bitcoin = require('bitcoinjs-lib');
var Chain = require('chain-node');
var chain = new Chain({blockChain: "testnet3"});
var b = new Buffer("Hello, world.");
var t = new bitcoin.Transaction();
t.addInput("ca7e12c753bd2a268e6f038509d72f3c44fd24064ed5ef8cde13ec987d495a64", 0);
@ryandotsmith
ryandotsmith / chain-websockets.html
Created Nov 30, 2014
Chain jQuery Notifications Websockets Example
View chain-websockets.html
<!doctype html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
</head>
<body>
<ul id="thashlist"></ul>
</body>
<script type="text/javascript">
$(function() {
@ryandotsmith
ryandotsmith / chain-notifications.js
Created Nov 29, 2014
Chain Node.js Notifications Example
View chain-notifications.js
var express = require('express');
var bodyParser = require('body-parser');
var chain = require('chain-node');
chain.apiKeyId = 'YOUR-API-KEY-ID';
chain.apiKeySecret = 'YOUR-API-KEY-SECRET';
var app = express();
app.use(bodyParser.json());
app.post('/', function (req, res) {
@ryandotsmith
ryandotsmith / s_queue.rb
Last active Aug 29, 2015
Multi-threaded SQS Ruby Worker. I have tests. Maybe this is a gem? Lemme know if you find it useful.
View s_queue.rb
require 'aws-sdk'
require 'json'
module SQSW
class SQueue
MissingQueue = Class.new(StandardError)
def initialize(url = nil)
raise(MissingQueue, "Missing queue_url") if url.nil?
@q = find_queue(url)
@ryandotsmith
ryandotsmith / confidence.js
Last active Aug 29, 2015
Demonstrate transaction confidence using Chain.com's Bitcoin API
View confidence.js
var chain = require('chain-node');
var confidant = function(txid, retries, cb) {
chain.getTransaction(txid, function(err, resp) {
if(resp.propagation_level > 0.9) {
cb(resp.propagation_level);
} else {
if(retries > 60) {
cb(null);
} else {
@ryandotsmith
ryandotsmith / webhooks.js
Last active Jun 20, 2016
Chain.com Webhooks Example
View webhooks.js
/*
Chain's Webhooks system will send an HTTP request
to our app with an event type of 'address-transaction'.
The body of the request will contain Chain's transaction
object. We can use this payload to do whatever we want!
*/
app.post('/', function (req, res) {
if (req.body['event'] == 'address-transaction') {
sendSMS(req.body.transaction)
res.send('OK\n');
@ryandotsmith
ryandotsmith / cond_test.go
Last active Aug 29, 2015
sync.Cond test cases
View cond_test.go
package main
import (
"testing"
"sync"
"sync/atomic"
)
type EasyCond struct {
m *sync.Mutex