我将使用OP_RETURN操作码将一些数据存储在比特币区块链中。为此,我关注this blog这是我的代码,
require 'bitcoin'
Bitcoin.network = :bitcoin
include Bitcoin::Builder
prev_hash = "655e480ea5b86158ed322fee71309a562718ec671126842612b7da66199590ec"
hex_tx = "01000000013542a7313111c814f35bea27ebf38bc9155ef1ad574ca443911a0e5792207049040000006b483045022100aedc2702a79acfc31b9874d331d4314b259e0dc7bc65e604631dabde764e19800220296c93e9250c5ec9348fdaa0a3f256ad10eedd08f01f9923599ba2072e147dbe0121035ef1c06deb3d74fc0f177da633fd18dc2cd8bb01341dde36212309252ccdbbe0feffffff1bd7220100000000001976a914b96894bdb2c791eb54e7905a04fd3544675ff65388ac13d91a000000000017a914fec5020d284b9d1e79bef155c55938728cfdf5d5873faa1e000000000017a914b910aa63eed5f8565b5f64b5bf541a3cbe16b5aa8772ed2c00000000001976a914c83b906199bf4bca25867bdd253918beae801fd988ac36921600000000001976a914eddda481a141396f4beae20a0d4ce1569b39b36888ac705510000000000017a914a55bd1266269cc355efdedcb73e6bae2450fc5cf8720f17400000000001976a9146e1de35ffa8ed3207668ef25814d63901fe36d9088ac204e0000000000001976a9149b0552a7ee0a46d0dd63563d705ed7c99248607588ac6ebc0000000000001976a9145b15d20b730bc7b8bac1c5751185a0ddc6a5e84b88ac9c820400000000001976a9146483d0c22793b02ca913b9d4cdd77b6fd11beef188acd8ba0d00000000001976a914aeb396e8c15fe8ccd98a48a95efb1711f928667988ac53ab8101000000001976a9144e4e0589e9e2e5cbbd08b8735dd86023cdb7776388acc0a90800000000001976a914c501696212c69a539661eec7a9be110b0e95bf3688acd60c1700000000001976a91400d1c4c86e07a1ca51d22fc2c5c9be7bc18de66388ac175e0100000000001976a914bcdc38ca84908728fb517dcfc39ddf255c98ab7e88ac000215000000000017a9149c2ae176ad505275fa9b0dc4dcaa8199c96143ea87b9130100000000001976a91464f5e8707053510e7edef90b187a511031ee51e288ace5104000000000001976a91428943bc0aec7c9f96c4199c46a071cf9eca2739588ac0c8b08000000000017a9149bf1c3e8e8cacf62381be7abd6e81066351147e987679f0900000000001976a914dc2814782770cd9b55f20ef71c9ac7b2248d613f88ac08870c00000000001976a9144f8ced0dd17f045dc38789a75f341b6c2d211c5988ac0b2a0300000000001976a914054d3d29d910576e023a435009dc85fb3e80a63a88ac25bf0d00000000001976a914de03193bfc08d90b5541dda254ee4972e7f740e488ac376b70000000000017a914c6707ca3ca1bb3693fcd198560d7e4070aa1b36f8764b61701000000001976a914572f90b0087004e504a723be4c1082d91b56d91c88acc02f5501000000001976a914b0271c737db4f88864ef7d529f1ea6862b31eb0a88acbbc7d501000000001976a914e1a10f15699e404a449c4c906e0fd368d11f923788ac8bb70700"
binary = [hex_tx].pack("H*")
prev_tx = Bitcoin::Protocol::Tx.new(binary)
prev_out_index = 0
print prev_tx
value = prev_tx.outputs[prev_out_index].value - 10_000
recipient = "1ACqAAkGcHefeJDrWguH2sCXTYS9yFxmRT"
key = Bitcoin::Key.from_base58("KEY")
# Build the transaction
new_tx = build_tx do |t|
# Construct the input to the transaction using the previous transaction we loaded from tx.json
t.input do |i|
i.prev_out prev_tx.hash
i.prev_out_index prev_out_index
i.signature_key key
end
t.output do |o|
o.value value
o.script { |s| s.recipient recipient }
end
t.output do |o|
o.to "secret message".unpack("H*"), :op_return
o.value 0
end
end
puts "Hex Encoded Transaction:\n\n"
puts new_tx.to_payload.unpack("H*")[0]
puts "\n\n"
puts "JSON:\n\n"
puts new_tx.to_json
为此,我正在关注JSON输出。
{
"hash":"05890e185b40d94586081af4236ab27b412dd19ad26fbe3c2380d61f336a722a",
"ver":1,
"vin_sz":1,
"vout_sz":2,
"lock_time":0,
"size":110,
"in":[
{
"prev_out":{
"hash":"655e480ea5b86158ed322fee71309a562718ec671126842612b7da66199590ec",
"n":0
},
"scriptSig":""
}
],
"out":[
{
"value":"0.00064455",
"scriptPubKey":"OP_DUP OP_HASH160 64f5e8707053510e7edef90b187a511031ee51e2 OP_EQUALVERIFY OP_CHECKSIG"
},
{
"value":"0.00000000",
"scriptPubKey":"OP_RETURN 736563726574206d657373616765"
}
]
}
当我搜索我的交易05890e185b40d94586081af4236ab27b412dd19ad26fbe3c2380d61f336a722a
时,区块链资源管理器说未找到交易。这有什么不对?
答案 0 :(得分:2)
您已创建了该交易,但未将其广播到比特币网络。
创建原始交易后,您应签署并发送交易。