Author

Topic: Can you spend to a custom scriptPubKey with Bitcoin Core? (Read 198 times)

sr. member
Activity: 355
Merit: 268
http://bitcoin-script-debugger.visvirial.com/?input=OP_1


Outputs can be… you know what i cant explain just check out the tool Wink.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
A custom script should be derived into an address to be useable in createrawtransaction, thus to create a UTXO, send bitcoins to the derived address normally.

Most likely it would require feeding the transaction parameters with the custom script into custom software (might even be just a hacked up C program) that outputs a raw transaction which can then be signed and broadcasted using Bitcoin Core - since achow said they can't be created in Core anyway.
legendary
Activity: 2394
Merit: 5531
Self-proclaimed Genius
If you want to spend a custom script's UTXO [...]
I don't want to spend a custom script's UTXO. I want to create the custom script's UTXO.
A custom script should be derived into an address to be useable in createrawtransaction, thus to create a UTXO, send bitcoins to the derived address normally.
staff
Activity: 3374
Merit: 6530
Just writing some code
No, you cannot.
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
send RPC call has a parameter in the JSON dictionary of the first argument to allow you to specify arbitrary hex data for an address (which I assume represents a locking script).
Yes, but you can only input an address there. P2PKH, P2SH, P2WPKH, P2WSH and P2TR (that I have forgotten to mention in OP). Not a custom script.

As you can see, it does not specifically define the function of "data", nor gives any examples that use it, so this is my best-guess assumption.
The value of data is taken as OP_RETURN data.

Code:
(network: testnet)
input: 46f1bfbe99e12841841e131b8ce04c4708881d8facc4729c16c97d78bcfad3c8
vout: 0
data: aa206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d619000000000087 (OP_HASH256 OP_PUSHBYTES_32 6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000 OP_EQUAL)

Code: ("Bitcoin Core")
createrawtransaction "[{\"txid\":\"46f1bfbe99e12841841e131b8ce04c4708881d8facc4729c16c97d78bcfad3c8\",\"vout\":0}]" "[{\"data\":\"aa206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d619000000000087\"}]"

0200000001c8d3fabc787dc9169c72c4ac8f1d8808474ce08c1b131e844128e199bebff1460000000000ffffffff010000000000000000256a23aa206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d61900000000008700000000

decoderawtransaction 0200000001c8d3fabc787dc9169c72c4ac8f1d8808474ce08c1b131e844128e199bebff1460000000000ffffffff010000000000000000256a23aa206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d61900000000008700000000

{
  "txid": "b5a051fa0281d3f6b1023c8517f47011faef9e2de6e315cd71ed60ded9aee8f0",
  "hash": "b5a051fa0281d3f6b1023c8517f47011faef9e2de6e315cd71ed60ded9aee8f0",
  "version": 2,
  "size": 97,
  "vsize": 97,
  "weight": 388,
  "locktime": 0,
  "vin": [
    {
      "txid": "46f1bfbe99e12841841e131b8ce04c4708881d8facc4729c16c97d78bcfad3c8",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_RETURN aa206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d619000000000087",
        "hex": "6a23aa206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d619000000000087",
        "type": "nulldata"
      }
    }
  ]
}

See?

My assumption is the "data" key-value pair in the output is just OP_RETURN, it wont process scripts;
Reason is, it automatically prepend 0x6A to the value which is OP_RETURN.
Exactly.

If you want to spend a custom script's UTXO [...]
I don't want to spend a custom script's UTXO. I want to create the custom script's UTXO.
legendary
Activity: 2394
Merit: 5531
Self-proclaimed Genius
But, from what I can see in the examples, you can either create a script that pays to an address or to an OP_RETURN.

My question is, can you create custom scripts with createrawtransaction, besides those four?
My assumption is the "data" key-value pair in the output is just OP_RETURN, it wont process scripts;
Reason is, it automatically prepend 0x6A to the value which is OP_RETURN.

The "address" key-value pair will only take addresses and the amount to be sent.

-Title-
If you want to spend a custom script's UTXO, its txid and vout should be entered in the inputs array of createrawtransaction,
then indicate the custom "scriptPubKey", "redeemScript" or "witnessScript" in prevtxs when signing the transaction: signrawtransactionwithkey
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
send RPC call has a parameter in the JSON dictionary of the first argument to allow you to specify arbitrary hex data for an address (which I assume represents a locking script).

You can see for yourself in the documentation:

Quote
send [{"address":amount},{"data":"hex"},...] ( conf_target "estimate_mode" fee_rate options )                                                         
                                                                                                                                                     
EXPERIMENTAL warning: this call may be changed in future releases.                                                                                   

Send a transaction.                 

Arguments:                           
1. outputs                               (json array, required) The outputs (key-value pairs), where none of the keys are duplicated.
                                         That is, each address can only appear once and there can only be one 'data' object.
                                         For convenience, a dictionary, which holds the key-value pairs directly, is also accepted.
     [                               
       {                                 (json object)                                                                                               
         "address": amount,              (numeric or string, required) A key-value pair. The key (string) is the bitcoin address, the value (float or
string) is the amount in BTC
       },                           
       {                                 (json object)                                                                                               
         "data": "hex",                  (string, required) A key-value pair. The key must be "data", the value is hex-encoded data
       },                           
       ...                           
     ]
...etc

As you can see, it does not specifically define the function of "data", nor gives any examples that use it, so this is my best-guess assumption.
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
As far as I know, with Core you can only create transaction with createrawtransaction. But, from what I can see in the examples, you can either create a script that pays to an address or to an OP_RETURN.

My question is, can you create custom scripts with createrawtransaction, besides those four?
Code:
OP_DUP OP_HASH160  OP_EQUALVERIFY OP_CHECKSIG (for P2PKH)
OP_HASH160 OP_EQUAL (for P2SH)
OP_0 OP_PUSHBYTES_20 (for P2WSH)
OP_RETURN
Jump to: