Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Chain.com OP_RETRURN Transaction - Create Bitcoin OP_RETURN Transactions in Ruby
require 'bitcoin'
require 'chain'
Chain.block_chain = 'testnet3'
Bitcoin.network = :testnet3
include Bitcoin::Builder
key = Bitcoin::Key.from_base58("cVVBKRBMoPLJSSMW7cM3hji7VmXz1zJWX3DypcjPcWpRBMEu2xF7")
builder = Bitcoin::Builder::TxBuilder.new
builder.input do |i|
i.prev_out("350d8714c734fdd75273259c4f06e1a5cb5ecebf182cf364a69e969c996384c1")
i.prev_out_index(1)
i.prev_out_script(["76a914a47fb04649d4b63d791462c0ac6b065dce8a994d88ac"].pack('H*'))
i.signature_key(key)
end
builder.output do |o|
o.value(0)
o.script {|s| s.type(:op_return); s.recipient(["hello from chain"].pack('H*'))}
end
builder.output do |o|
o.value(1000000)
o.script {|s| s.recipient(key.addr)}
end
puts Chain.send_transaction(builder.tx.to_payload.unpack('H*')[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment