Build specific scriptPubKey

by Timur Panzhiev   Last Updated September 21, 2018 10:27 AM

Help!

I try to build specific scriptPubKey for output using bitcoinj library. It should look like this:

1 OP_DROP 54657374313131 5 OP_2DROP 3355185 OP_DROP OP_DUP OP_HASH160 1afd5d7cead4ef5452b096989208b85fb480d3f2 OP_EQUALVERIFY OP_CHECKSIG",

Here is my code:

Address address = new Address(params, addressToSend);
int OP_NAME_NEW = 1;
String name = "Test123"
String expiresIn = "5";
String value = "123";

Script script = new ScriptBuilder()
 .data(ByteBuffer.allocate(Integer.SIZE/8).putInt(OP_NAME_NEW).array())
 .op(ScriptOpCodes.OP_DROP)
 .data(name.getBytes())
 .data(ByteBuffer.allocate(Integer.SIZE/8).putInt(Integer.valueOf(expireIn)).array())
 .op(ScriptOpCodes.OP_2DROP)
 .data(value.getBytes())
 .op(ScriptOpCodes.OP_DROP)
 .op(ScriptOpCodes.OP_DUP)
 .op(ScriptOpCodes.OP_HASH160)
 .data(address.getHash160())
 .op(ScriptOpCodes.OP_EQUALVERIFY)
 .op(ScriptOpCodes.OP_CHECKSIG)
 .build();

transaction.addOutput(Coin.valueOf(amountToSend), script);

Log.d(TAG, "Script: " + script.toString());

And that's what I have in the end after raw transaction parsing:

"16777216 OP_DROP 54657374313131 83886080 OP_2DROP 3355185 OP_DROP OP_DUP OP_HASH160 1afd5d7cead4ef5452b096989208b85fb480d3f2 OP_EQUALVERIFY OP_CHECKSIG"

Here is the rawTx:

010000004953a95a0184057e0e1d06dd1996638c67787545c583694f987986334a4919bcf3546aebd0000000006b483045022100f72e24917d2fa0274a5dec6848db5b6dc8d2834fd05cdb2652a91ec1439a004002203ca53e09917c361193c3498c8a902f8d17151f2fc9f2a0003ded8eb6dcbc7ef00121025dc5dd91ef93722cfd4c6505a0436dd72ae50809c825e0214518fa2a0c5ef0ffffffffff01640000000000000032040000000175075465737431313104000000056d033132337576a914ae1da8becdd0fff6a931318d1d519c1aa8639b9088ac00000000

And log:

Script: PUSHDATA(4)[00000001] DROP PUSHDATA(7)[54657374313131] PUSHDATA(4)[00000005] 2DROP PUSHDATA(3)[313233] DROP DUP HASH160 PUSHDATA(20)[ae1da8becdd0fff6a931318d1d519c1aa8639b90] EQUALVERIFY CHECKSIG

What I`m doing wrong?



Answers 1


@Timur Panzhiev
Can you provide your code?

blueberry082
blueberry082
September 21, 2018 10:03 AM

Related Questions


How to sign a transaction using BitcoinJ

Updated November 14, 2017 17:27 PM