bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I consume a UTxO from a script based address (P2SH)

leo42 opened this issue · comments

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)

This can be done with bitcoinjs

But i suggest you read our transaction example first

https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts

It seems that no more discussion is needed