Skip to content

Latest commit

 

History

History
86 lines (71 loc) · 2.8 KB

README.md

File metadata and controls

86 lines (71 loc) · 2.8 KB
  • Send btc: Tạo psbt sau đó kí bằng ví.

  • Demo:

    • Step 1: Generate psbt

      // Create psbt
      const btcPsbt = new BtcPsbt(bitcoin.networks.testnet);
      
      // Add inputs
      const inputs: TxInput[] = [
         {
            hash: "6e7307c...0eddabbd", // prev ix id
            index: 1, // output index - 1,
            nonWitnessUtxo: Buffer.from("02000000000...36e0100000000", "hex") // prev tx hex
      // // If this input was segwit, instead of nonWitnessUtxo,
      // // you would add a witnessUtxo as follows. The scriptPubkey and the value only are needed.
          // witnessUtxo: {
          //   script: Buffer.from(
          //     '76a9148bbc...18d88ac', // ScriptPubKey
          //     'hex',
          //   ),
          //   value: 90000,
          // },
         }
      ]
      
      // Add outputs
      const outputs: TxOutput[] = [
          { address: 'tb1qkd5...szesvjf7', value: 100 }, // to address
          { address: 'tb1qqjmc...x4w4lgwsku0', value: 16250 } // from address - to pay fee (optional)
      ]
      
      // Add memos
      const newOpreturns: string[] = ["This is a new OpReturn message", "Another OpReturn message"];
      
      // Update psbt
      btcPsbt.updatePsbt(inputs, outputs, newOpreturns);
      
      // Generated Psbt 
      const updatedPsbtHex = btcPsbt.toHex();
      • View data in https://mempool.space/testnet/

        • hash: Previous tx id image

        • index: Output index - 1 image

        • nonWitnessUtxo: Buffer previous transaction hex image

        • witnessUtxo: scriptPubkey & value image

    • Step 2: Sign psbt ( https://docs.unisat.io/dev/unisat-developer-service/unisat-wallet#signpsbt )

      try {
         let res = await window.unisat.signPsbt( "70736274ff01007d....", {
            autoFinalized:false,
            toSignInputs:[
               {
                  index: 0,
                  address: "tb1q8h8....mjxzny",
               },
            ]  
         }
      );
      console.log(res)
      } catch (e) {console.log(e)}
    • Step 3: Push psbt ( https://docs.unisat.io/dev/unisat-developer-service/unisat-wallet#pushpsbt )

      try {
         let res = await window.unisat.pushPsbt("70736274ff01007d....");
         console.log(res)
      } catch (e) {
         console.log(e);
      }
  • Debug: