How to Build and Sign a BTC Transaction Type 2 Using Wallet Core?
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?
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))
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: https://github.com/trustwallet/wallet-core/pull/3848
Hi @ronaldoguedess, sorry for the late update. You can now use BitcoinV2 protocol (please take a look at the unit tests as examples) https://github.com/trustwallet/wallet-core/pull/3848