Author

Topic: LedgerJS BTC transaction Issue (Read 112 times)

copper member
Activity: 250
Merit: 412
Building A Crypto Empire
August 04, 2021, 09:29:46 PM
#3
You're using SegWit UTXOs... have you included the appropriate "segwit" arguments? Huh

from LedgerJS repo:

Code:
createPaymentTransactionNew
To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters

Parameters
...
-redeem script: is the optional redeem script to use when consuming a Segregated Witness input
...
-segwit: is an optional boolean indicating wether to use segwit or not
...
-useTrustedInputForSegwit: trust inputs for segwit transactions

Note, you may not need to specify all of these arguments for your particular transaction.

I have been reading for the past few days in depth about raw transactions. I did figure out the note you have put. Having that said I am still not 100% certain on what goes as param in that call.

I really appreciate you commenting on this post, Working on more testing tonight. Are you able to guide me on what should go in that call? Can you use the data I have provided to show an example?

Will update this post tonight on latest tests done.

Edit: figured it out, its fine now.
HCP
legendary
Activity: 2086
Merit: 4314
August 03, 2021, 07:15:50 PM
#2
You're using SegWit UTXOs... have you included the appropriate "segwit" arguments? Huh

from LedgerJS repo:

Code:
createPaymentTransactionNew
To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters

Parameters
...
-redeem script: is the optional redeem script to use when consuming a Segregated Witness input
...
-segwit: is an optional boolean indicating wether to use segwit or not
...
-useTrustedInputForSegwit: trust inputs for segwit transactions

Note, you may not need to specify all of these arguments for your particular transaction.
copper member
Activity: 250
Merit: 412
Building A Crypto Empire
July 29, 2021, 03:35:59 PM
#1
Hello guys,


I am having some issues while using LEDGER JS API (BTC APP), can anyone please have a look at it if possible and help me with an example? I am stuck at creating a transaction.

https://github.com/LedgerHQ/ledgerjs/tree/master/packages/hw-app-btc

I was able to fetch address etc from Ledger device, create and sign a message. Cannot create and sign a transaction tho.

The address I am using is BTC-Testnet address:
tb1qq9jaj4qxxemdmnywmxrphtn37krnwx9pwmelgg

I have put faucet balance in it, transaction hash:
60434b49d2b7fa78c8f31d9717fb6961e19ace6f4b42e7762335b8917ce80dbb

Example from Ledger BTC APP:

btc.createTransaction({
inputs: [ [tx1, 1] ],
associatedKeysets: ["0'/0/0"],
outputScriptHex: ""
}).then(res => ...);


I got tx1 from unspent transaction "60434b49d2b7fa78c8f31d9717fb6961e19ace6f4b42e7762335b8917ce80dbb" hex:

0200000000010193e2a2cbeda1a6a8f977f4e4002013a6a2f5df9bb0a2db4c4e88c9552c0558480 000000017160014c4f016563aa770029be0b5c522346abb86ca5242feffffff0200f11500000000 001600140165d954063676ddcc8ed9861bae71f5873718a1ab5bcefe00000000160014c459093d5 fc0e97ceac83e8fb1da822613d019a40247304402206641c5508dd5f850a818920426cdb506a656 0575c47c19ab7f565440395809db02204cf120a10a42f9d0258fab56a74cfe498acf9a290520d84 cb82c014bb58d1de001210346d5eba094f35dc2e189f2692017e54af3e92f8bbf65a84819cfb0ea b60aded91b2a1e00

Then done:

const tx1 = btc.splitTransaction("0200000000010193e2a2cbeda1a6a8f977f4e4002013a6a2f5df9bb0a2db4c4e88c9552c0558480 000000017160014c4f016563aa770029be0b5c522346abb86ca5242feffffff0200f11500000000 001600140165d954063676ddcc8ed9861bae71f5873718a1ab5bcefe00000000160014c459093d5 fc0e97ceac83e8fb1da822613d019a40247304402206641c5508dd5f850a818920426cdb506a656 0575c47c19ab7f565440395809db02204cf120a10a42f9d0258fab56a74cfe498acf9a290520d84 cb82c014bb58d1de001210346d5eba094f35dc2e189f2692017e54af3e92f8bbf65a84819cfb0ea b60aded91b2a1e00");
const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');

result I got from serializeTransaction call is:

010193e2a2cbeda1a6a8f977f4e4002013a6a2f5df9bb0a2db4c4e88c9552c05584800000000171 60014c4f016563aa770029be0b5c522346abb86ca5242feffffff0200f115000000000016001401 65d954063676ddcc8ed9861bae71f5873718a1ab5bcefe00000000160014c459093d5fc0e97ceac 83e8fb1da822613d019a40247304402206641c5508dd5f850a818920426cdb506a6560575c47c19 ab7f565440395809db02204cf120a10a42f9d025


from LedgerJS repo:

Code:
createPaymentTransactionNew
To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters

Parameters
-arg: CreateTransactionArg
-inputs: is an array of [ transaction, output_index, optional redeem script, optional sequence ] where- transaction is the previously computed transaction object for this UTXO
-output_index: is the output in the transaction used as input for this UTXO (counting from 0)
-redeem script: is the optional redeem script to use when consuming a Segregated Witness input
-sequence: is the sequence number to use for this input (when using RBF), or non present
-associatedKeysets: is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
-changePath: is an optional BIP 32 path pointing to the path to the public key used to compute the change address
-outputScriptHex: is the hexadecimal serialized outputs of the transaction to sign
-lockTime: is the optional lockTime of the transaction to sign, or default (0)
-sigHashType: is the hash type of the transaction to sign, or default (all)
-segwit: is an optional boolean indicating wether to use segwit or not
-initialTimestamp: is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)

-additionals list of additionnal options- "bech32" for spending native segwit outputs
"abc" for bch
"gold" for btg
"bipxxx" for using BIPxxx
"sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)

-expiryHeight: is an optional Buffer for zec overwinter / sapling Txs
-useTrustedInputForSegwit: trust inputs for segwit transactions

Examples
btc.createTransaction({
inputs: [ [tx1, 1] ],
associatedKeysets: ["0'/0/0"],
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
}).then(res => ...);



guessing all this is basic transaction creation, I have no idea & need help.


I want to send balance from address: tb1qq9jaj4qxxemdmnywmxrphtn37krnwx9pwmelgg
to this address: tb1qrqj2s4ed48jg7s6j34c0jmpyh4d8wu5p5jt44n
amount to be sent: 0.00253


Thanks guys, appreciated in advance.
Jump to: