bitcoinjs-lib
bitcoinjs-lib copied to clipboard
How do I consume a UTxO from a script based address (P2SH)
It seems like all the P2SH are classified under the hood into specific types of script.
For my needs I want to have multiple address that are owned by the same set of multisig participants. Is this possible ?
I managed the address generation with the following snippet
`function getAddress(index,m, keys){
const pubkeys = keys.map(key => Buffer.from(key, 'hex'));
const multisigScript = bitcoin.script.compile([
Buffer.from(index.toString(16).padStart(8, '0'), 'hex').reverse(),
bitcoin.opcodes.OP_CHECKLOCKTIMEVERIFY,
bitcoin.opcodes.OP_DROP,
...pubkeys,
bitcoin.opcodes.OP_RESERVED + m,
bitcoin.opcodes.OP_CHECKMULTISIG,
]); const p2shAddress = bitcoin.payments.p2sh({ redeem: { output: multisigScript, network: bitcoin.networks.testnet, // Replace with the appropriate network if needed (e.g., bitcoin.networks.testnet) }, }); return p2shAddress.address; }`
I also need to be able and extract the transaction and signatures as the participants are all going to be independent and will need to pass signatures amongst each other to complete the transaction,(someone else is also asking about that)