Created
December 8, 2014 03:57
-
-
Save ryandotsmith/e913ee8e6becc1321d0f to your computer and use it in GitHub Desktop.
Creating op-return transactions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the transaction created by this program:
http://explorer.chain.com/transactions/d0a12fb3f5fd2536decddfb6701077b6312bc3fe4c29df51a84f19eec01fe2fc#!transaction-op-return