Skip to content

Instantly share code, notes, and snippets.

Embed
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"));
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

ryandotsmith commented Dec 8, 2014

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