bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.
MIT License
5.7k stars 2.11k forks source link

Error "64: no-witness-yet" #1614

Closed Droppix closed 4 years ago

Droppix commented 4 years ago

Hello,

I try to create/send transaction on DOGE Testnet (send : 2NEVg7yQyW5n8Q1hBSUK57H6q43LZVqjFiS to 2NCPCBqu3iXb5YyosBNszXzFAmUfhSosC9K with amount = 100 tDOGE)

 input from UTXO :
 input.address = "2NEVg7yQyW5n8Q1hBSUK57H6q43LZVqjFiS"
 input.txid = "44b0395211eaf64bae8d0d05c0567326afdf4f5650fed8d35ca8d5e764ddf446"
 input.vout = 0
 input.hex = "01000000015b3dc6f64124c128da7d8727f5c189cadd6519d0b325aafcfb119f0d8e02cba2000000004847304402200c963f765b45ec6ae5bc6e5aba1b4e08480ce6e8bb39d771def850d648ff3a8102204a2cad1856b8b73ed889b619f70bc0701f4adf9893ed562bd4958fabb5424a3b01feffffff010010a5d4e800000017a914e91647805102bb3c5c344c050af1898838420497876a1e2700"

 addrsWallet[0] = { public_key: xxx, private_key: xxx} for address "2NEVg7yQyW5n8Q1hBSUK57H6q43LZVqjFiS"
 const ecpair = bitcoinjs.ECPair.fromWIF(addrsWallet[0].private_key, this.network) // Testnet
 let p2shObj = bitcoinjs.payments.p2sh({
      redeem: bitcoinjs.payments.p2wpkh({ pubkey: ecpair.publicKey, network: this.network }),
 })
 const redeemScript = p2shObj.redeem.output
 const scriptPubKey = p2shObj.output.toString('hex')

 psbt.addInput({
    hash: input.txid, 
    index: input.vout,
    //nonWitnessUtxo: Buffer.from(input.hex , 'hex'),
    witnessUtxo: {
        script: Buffer.from(scriptPubKey, 'hex'),
        value: 1000000000000
    }    
    redeemScript: redeemScript,
 })

 psbt.addOutput({address: "2NCPCBqu3iXb5YyosBNszXzFAmUfhSosC9K", value: 10000000000}) 
 psbt.addOutput({address: "2NEVg7yQyW5n8Q1hBSUK57H6q43LZVqjFiS", value: 989999999999}) 

 psbt.signInput(0, ecpair)

 let validated = psbt.validateSignaturesOfInput(0)
 psbt.finalizeAllInputs()

 let rawTx = psbt.extractTransaction().toHex()

 /*
 rawTx = "0200000000010146f4dd64e7d5a85cd3d8fe50564fdfaf267356c0050d8dae4bf6ea115239b044000000001716001495// e4793a929dd3ca4db20a3824b663d6a3855184ffffffff0200e40b540200000017a914d1ec36e5dd24045c55aeb4de979a34acd884b38787ff2b9980e600000017a914e91647805102bb3c5c344c050af1898838420497870247304402206a627408526285059da35953f79f62817129a51392acbebe39d32a9d601a0d7e02205cc3e550e88d69070ccea64a7498f007595d08618be141cf3425b94ffa7648400121036356fadba73da8dbd04d677c9654228d46a76ae946472c2285e5c80b72ca4c9100000000"
*/

let err = send (rawTx) 

I sent 'rawTx' to DOGE Network Testnet, and I obtained an error : **"-26: 64: no-witness-yet"**

I tried a lot of things, but without success... I would appreciate your help... Thanks

lukechilds commented 4 years ago

You're adding a segwit UTXO to the PSBT, I'm not too familiar with Dogecoin but the error looks like maybe it doesn't support segwit?

Droppix commented 4 years ago

Yet if I look at the transactions in the explorer, it seems to me that we can see the segwit addresses.... cf: https://blockexplorer.one/doge/testnet/tx/4df614b42a8bd9a0bb01ff040c2ee4363df02e7f3a75cc541c588cad77d2d186

junderw commented 4 years ago

If you look at the Sigscript you can see it is clearly a multisig address.

P2SH does not equal "Segwit"

P2SH can mean anything, in the case of the tx you linked, those P2SH are non-segwit-multisig addresses.

Doge does not support segwit.

Droppix commented 4 years ago

Ok...So what should I do? What is the solution?

If I try :

psbt.addInput({
    hash: input.txid, 
    index: input.vout,
 })
...
 psbt.signInput(0, ecpair)

I obtain this: 
Error: Need a Utxo input item for signing

I try many solutions, but I don't found the good solution

junderw commented 4 years ago

There is no solution.

If you sent money to a segwit script on dogecoin it is not redeemable.

Droppix commented 4 years ago

I'm not sure I understand... It is not possible to send 'N' doge from 2NEVg7yQyW5n8Q1hBSUK57H6q43LZVqjFiS to 2NCPCBqu3iXb5YyosBNszXzFAmUfhSosC9K? (because they are segwit addresses) ? Or is it a problem of method?

(Sorry if my question seems stupid, but I'm a bit lost...)

junderw commented 4 years ago

It is not possible to send 'N' doge from 2NEVg7yQyW5n8Q1hBSUK57H6q43LZVqjFiS to 2NCPCBqu3iXb5YyosBNszXzFAmUfhSosC9K?

That is correct. It is not possible to spend dogecoins on 2NEVg7yQyW5n8Q1hBSUK57H6q43LZVqjFiS until dogecoin supports segwit, which it does not.

If dogecoin never supports segwit, your coins are lost forever.

If dogecoin supports segwit in 2 years, you will be able to spend the coins in 2 years.