Using the same public keys, the p2sh returned by `addmultisigaddress` differs from the one returned by `createmultisigaddress`



Summary:

Michele Federici wrote to the bitcoin-dev mailing list, stating that he was working on a function to derive the pay-to-script-hash from a multisig script and noticed a discrepancy between `addmultisigaddress` and `createmultisigaddress` methods. He checked his implementation and found it was correct, but his output address was different from the `addmultisigaddress` output. However, when he tried the `createmultisigaddress` method, using the same public keys, the output matched his. The `redeemScript` was the same for both methods, only the addresses were different. The reason for this discrepancy is due to the address types in use. `addmultisigaddress` uses the default address type of the wallet, which is p2sh-segwit. On the other hand, `createmultisig` uses a default address type of legacy. To have `createmultisig` get `addmultisigaddress`'s result, one needs to add the string "p2sh-segwit" to the end of the command. Similarly, to have `addmultisigaddress` get `createmultisig`'s result, one needs to add the string "legacy" to the end of the command.


Updated on: 2023-05-20T20:10:57.724197+00:00