简体   繁体   中英

RPC call on bitcoind for adding P2SH

I have been searching around a lot and I can't seem to figure this out.

I want to create a transaction with a custom P2SH address by using Bitcoin Core's RPC calls. I found there is a redeemScript field in signrawtransaction so I'm assuming this is where I should send a hex encoding of my script. But this needs a txid , so should I first use createrawtransaction with the output being the address I want to send to and then sign the transaction with the script included?

I saw there is already a createmultisig call and since that is also P2SH it seems there should be something similar for other P2SH transactions.

Any idea how I can solve this or where I can find more information on this?

If I understand it correctly according to this section of the bitcoin book, you are supposed to create a hash out of your script and then convert this hash into an address which allows you to use the regular sendtoaddress rpc call to send coins to the address.

Another important part of the P2SH feature is the ability to encode a script hash as an address, as defined in BIP-13. P2SH addresses are Base58Check encodings of the 20-byte hash of a script, just like bitcoin addresses are Base58Check encodings of the 20-byte hash of a public key. P2SH addresses use the version prefix "5," which results in Base58Check-encoded addresses that start with a "3."

Now, Mohammed can give this "address" to his customers and they can use almost any bitcoin wallet to make a simple payment, as if it were a bitcoin address. The 3 prefix gives them a hint that this is a special type of address, one corresponding to a script instead of a public key, but otherwise it works in exactly the same way as a payment to a bitcoin address.

P2SH addresses hide all of the complexity, so that the person making a payment does not see the script.

Take a look at the whole section for how to convert the script to a hash.

You can download the executable that is used in the book here: https://github.com/libbitcoin/libbitcoin-explorer/releases

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM