Skip to content

Instantly share code, notes, and snippets.

Created December 8, 2014 03:57
What would you like to do?
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"));
chain.sendTransaction(t.toHex(), function(err, resp) {
console.log("error=" + util.inspect(err));
console.log("response=" + util.inspect(resp, {depth: null}));
Copy link

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