Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Build and Sign a BTC Transaction Type 2 Using Wallet Core? #3874

Open
ronaldoguedess opened this issue Jun 1, 2024 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@ronaldoguedess
Copy link

When I build and sign a BTC transaction, it defaults to type 1. Is it possible to build and sign a type 2 BTC transaction using Wallet Core?
image

This is how I'm building the tx, how can I convert it to type 2? Btw, is there any advantage to using transaction type 2?

      //BUILD TX
            val scriptUTXO = BitcoinScript.lockScriptForAddress(addressFrom, CoinType.BITCOIN)
            val scriptHash = scriptUTXO.matchPayToWitnessPublicKeyHash()
            val redeemScriptHash = scriptHash.toHexString()
            val redeemScript = BitcoinScript.lockScriptForAddress(addressFrom, CoinType.BITCOIN).data()

            //INPUT
            val input = Bitcoin.SigningInput.newBuilder().apply {
                this.amount = amount       //1962973
                if (maxAmount) {
                    this.useMaxAmount = true //auto-sweep
                }
                this.hashType = BitcoinSigHashType.ALL.value()
                this.toAddress = addressToTss //Receiver ADDRESS (TO) MUST BE TSS
                this.changeAddress = changeAddressLeftOver.ifEmpty { addressFrom } //LEFT OVER
                this.byteFee = byteFee.toLong()
                this.coinType = CoinType.BITCOIN.value()
                this.fixedDustThreshold = 1000 // or 546 for P2PKH, P2WPKH transfers
                this.dustPolicyCase
                //this.disableDustFilter = true
                this.addPrivateKey(ByteString.copyFrom(hexPrivateKey.hexStringToByteArray()))  //HEX
            }
            input.putScripts(redeemScriptHash, ByteString.copyFrom(redeemScript))
@ronaldoguedess ronaldoguedess added the enhancement New feature or request label Jun 1, 2024
@satoshiotomakan
Copy link
Collaborator

Hi @ronaldoguedess, at this moment we don't allow to specify version 1, but it will be possible in a few weeks when Bitcoin V2 refactoring comes: #3848

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants
@ronaldoguedess @satoshiotomakan and others