Skip to content

Instantly share code, notes, and snippets.

@ryandotsmith
Created December 8, 2014 03:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryandotsmith/e913ee8e6becc1321d0f to your computer and use it in GitHub Desktop.
Save ryandotsmith/e913ee8e6becc1321d0f to your computer and use it in GitHub Desktop.
Creating op-return transactions
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);
t.addOutput("mr4CZmLR9pTv91jBgkDrvFnV29hZpr8yEn", 1000000);
t.addOutput(bitcoin.Script.fromChunks([bitcoin.opcodes.OP_RETURN, b]), 0);
t.sign(0, bitcoin.ECKey.fromWIF("KzRXiPFrTwPR7RRPfSSqLMvBFHAkncsUcehFTcZ1RMTUmjG9qE6P"));
console.log(t.toHex())
chain.sendTransaction(t.toHex(), function(err, resp) {
console.log("error=" + util.inspect(err));
console.log("response=" + util.inspect(resp, {depth: null}));
});
@ryandotsmith
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment