async genesisTokens(
    utxo,
    qty,
    changeAddress,
    genesisAddr,
    walletInfo,
    tokenUtxos
  ) {
    try {
      //console.log(`utxo: ${util.inspect(utxo)}`)

      // instance of transaction builder
      let transactionBuilder
      if (walletInfo.network === `testnet`)
        transactionBuilder = new this.BITBOX.TransactionBuilder("testnet")
      else transactionBuilder = new this.BITBOX.TransactionBuilder()

      //const satoshisToSend = Math.floor(bch * 100000000)
      //console.log(`Amount to send in satoshis: ${satoshisToSend}`)
      const originalAmount = utxo.satoshis
      const vout = utxo.vout
      const txid = utxo.txid

      // add input utxo to pay for transaction.
      transactionBuilder.addInput(txid, vout)

      // get byte count to calculate fee. paying 1 sat
      // Note: This may not be totally accurate. Just guessing on the byteCount size.
      // const byteCount = this.BITBOX.BitcoinCash.getByteCount(
      //   { P2PKH: 3 },
      //   { P2PKH: 5 }
      // )
      // //console.log(`byteCount: ${byteCount}`)
      // const satoshisPerByte = 1.1
      // const txFee = Math.floor(satoshisPerByte * byteCount)
      // console.log(`txFee: ${txFee} satoshis\n`)
      const txFee = 500

      // amount to send back to the sending address. It's the original amount - 1 sat/byte for tx size
      const remainder = originalAmount - txFee - 546 * 2
      if (remainder < 1)
        throw new Error(`Selected UTXO does not have enough satoshis`)
      //console.log(`remainder: ${remainder}`)

      // Generate the OP_RETURN entry for an SLP GENESIS transaction.
      //console.log(`Generating op-return.`)
      const { script, outputs } = this.generateOpReturn(tokenUtxos, qty)
      //console.log(`script: ${JSON.stringify(script, null, 2)}`)

      const data = BITBOX.Script.encode(script)
      //console.log(`data: ${JSON.stringify(data, null, 2)}`)

      // Add OP_RETURN as first output.
      transactionBuilder.addOutput(data, 0)

      // Send dust transaction representing tokens being sent.
      transactionBuilder.addOutput(
        this.BITBOX.Address.toLegacyAddress(genesisAddr),
        546
      )

      // Return any token change back to the sender.
      if (outputs > 1) {
        transactionBuilder.addOutput(
          this.BITBOX.Address.toLegacyAddress(changeAddress),
          546
        )
      }

      // Last output: send the change back to the wallet.
      transactionBuilder.addOutput(
        this.BITBOX.Address.toLegacyAddress(changeAddress),
        remainder
      )

      // Generate a keypair from the change address.
      const change = await appUtils.changeAddrFromMnemonic(
        walletInfo,
        utxo.hdIndex
      )
      //console.log(`change: ${JSON.stringify(change, null, 2)}`)
      const keyPair = this.BITBOX.HDNode.toKeyPair(change)

      // Sign the transaction with the private key for the UTXO paying the fees.
      let redeemScript
      transactionBuilder.sign(
        0,
        keyPair,
        redeemScript,
        transactionBuilder.hashTypes.SIGHASH_ALL,
        originalAmount
      )

      // Sign each token UTXO being consumed.
      for (let i = 0; i < tokenUtxos.length; i++) {
        const thisUtxo = tokenUtxos[i]

        // Generate a keypair to sign the SLP UTXO.
        const slpChangeAddr = await appUtils.changeAddrFromMnemonic(
          walletInfo,
          thisUtxo.hdIndex
        )

        const slpKeyPair = this.BITBOX.HDNode.toKeyPair(slpChangeAddr)
        //console.log(`slpKeyPair: ${JSON.stringify(slpKeyPair, null, 2)}`)

        transactionBuilder.sign(
          1 + i,
          slpKeyPair,
          redeemScript,
          transactionBuilder.hashTypes.SIGHASH_ALL,
          thisUtxo.satoshis
        )
      }

      // build tx
      const tx = transactionBuilder.build()

      // output rawhex
      const hex = tx.toHex()
      //console.log(`Transaction raw hex: `)
      //console.log(hex)

      return hex
    } catch (err) {
      console.log(`Error in genesisTokens()`)
      throw err
    }
  }
// Generates the SLP transaction in hex format, ready to broadcast to network.
Generates the SLP transaction in hex format, ready to broadcast to network.
Generates the SLP transaction in hex format ready to broadcast to network .
async genesisTokens(
    utxo,
    qty,
    changeAddress,
    genesisAddr,
    walletInfo,
    tokenUtxos
  ) {
    try {
      let transactionBuilder
      if (walletInfo.network === `testnet`)
        transactionBuilder = new this.BITBOX.TransactionBuilder("testnet")
      else transactionBuilder = new this.BITBOX.TransactionBuilder()
      const originalAmount = utxo.satoshis
      const vout = utxo.vout
      const txid = utxo.txid
      transactionBuilder.addInput(txid, vout)
      const txFee = 500
      const remainder = originalAmount - txFee - 546 * 2
      if (remainder < 1)
        throw new Error(`Selected UTXO does not have enough satoshis`)
      const { script, outputs } = this.generateOpReturn(tokenUtxos, qty)
      const data = BITBOX.Script.encode(script)
      transactionBuilder.addOutput(data, 0)
      transactionBuilder.addOutput(
        this.BITBOX.Address.toLegacyAddress(genesisAddr),
        546
      )
      if (outputs > 1) {
        transactionBuilder.addOutput(
          this.BITBOX.Address.toLegacyAddress(changeAddress),
          546
        )
      }
      transactionBuilder.addOutput(
        this.BITBOX.Address.toLegacyAddress(changeAddress),
        remainder
      )
      const change = await appUtils.changeAddrFromMnemonic(
        walletInfo,
        utxo.hdIndex
      )
      const keyPair = this.BITBOX.HDNode.toKeyPair(change)
      let redeemScript
      transactionBuilder.sign(
        0,
        keyPair,
        redeemScript,
        transactionBuilder.hashTypes.SIGHASH_ALL,
        originalAmount
      )
      for (let i = 0; i < tokenUtxos.length; i++) {
        const thisUtxo = tokenUtxos[i]
        const slpChangeAddr = await appUtils.changeAddrFromMnemonic(
          walletInfo,
          thisUtxo.hdIndex
        )
        const slpKeyPair = this.BITBOX.HDNode.toKeyPair(slpChangeAddr)
        transactionBuilder.sign(
          1 + i,
          slpKeyPair,
          redeemScript,
          transactionBuilder.hashTypes.SIGHASH_ALL,
          thisUtxo.satoshis
        )
      }
      const tx = transactionBuilder.build()
      const hex = tx.toHex()
      return hex
    } catch (err) {
      console.log(`Error in genesisTokens()`)
      throw err
    }
  }
async genesisTokens ( utxo , qty , changeAddress , genesisAddr , walletInfo , tokenUtxos ) { try { let transactionBuilder if ( walletInfo . network === ` ` ) transactionBuilder = new this . BITBOX . TransactionBuilder ( "testnet" ) else transactionBuilder = new this . BITBOX . TransactionBuilder ( ) const originalAmount = utxo . satoshis const vout = utxo . vout const txid = utxo . txid transactionBuilder . addInput ( txid , vout ) const txFee = 500 const remainder = originalAmount - txFee - 546 * 2 if ( remainder < 1 ) throw new Error ( ` ` ) const { script , outputs } = this . generateOpReturn ( tokenUtxos , qty ) const data = BITBOX . Script . encode ( script ) transactionBuilder . addOutput ( data , 0 ) transactionBuilder . addOutput ( this . BITBOX . Address . toLegacyAddress ( genesisAddr ) , 546 ) if ( outputs > 1 ) { transactionBuilder . addOutput ( this . BITBOX . Address . toLegacyAddress ( changeAddress ) , 546 ) } transactionBuilder . addOutput ( this . BITBOX . Address . toLegacyAddress ( changeAddress ) , remainder ) const change = await appUtils . changeAddrFromMnemonic ( walletInfo , utxo . hdIndex ) const keyPair = this . BITBOX . HDNode . toKeyPair ( change ) let redeemScript transactionBuilder . sign ( 0 , keyPair , redeemScript , transactionBuilder . hashTypes . SIGHASH_ALL , originalAmount ) for ( let i = 0 ; i < tokenUtxos . length ; i ++ ) { const thisUtxo = tokenUtxos [ i ] const slpChangeAddr = await appUtils . changeAddrFromMnemonic ( walletInfo , thisUtxo . hdIndex ) const slpKeyPair = this . BITBOX . HDNode . toKeyPair ( slpChangeAddr ) transactionBuilder . sign ( 1 + i , slpKeyPair , redeemScript , transactionBuilder . hashTypes . SIGHASH_ALL , thisUtxo . satoshis ) } const tx = transactionBuilder . build ( ) const hex = tx . toHex ( ) return hex } catch ( err ) { console . log ( ` ` ) throw err } }
Generates the SLP transaction in hex format, ready to broadcast to network.
Generates the SLP transaction in hex format ready to broadcast to network .
//console.log(`utxo: ${util.inspect(utxo)}`) // instance of transaction builder //const satoshisToSend = Math.floor(bch * 100000000) //console.log(`Amount to send in satoshis: ${satoshisToSend}`) // add input utxo to pay for transaction. // get byte count to calculate fee. paying 1 sat // Note: This may not be totally accurate. Just guessing on the byteCount size. // const byteCount = this.BITBOX.BitcoinCash.getByteCount( //   { P2PKH: 3 }, //   { P2PKH: 5 } // ) // //console.log(`byteCount: ${byteCount}`) // const satoshisPerByte = 1.1 // const txFee = Math.floor(satoshisPerByte * byteCount) // console.log(`txFee: ${txFee} satoshis\n`) // amount to send back to the sending address. It's the original amount - 1 sat/byte for tx size //console.log(`remainder: ${remainder}`) // Generate the OP_RETURN entry for an SLP GENESIS transaction. //console.log(`Generating op-return.`) //console.log(`script: ${JSON.stringify(script, null, 2)}`) //console.log(`data: ${JSON.stringify(data, null, 2)}`) // Add OP_RETURN as first output. // Send dust transaction representing tokens being sent. // Return any token change back to the sender. // Last output: send the change back to the wallet. // Generate a keypair from the change address. //console.log(`change: ${JSON.stringify(change, null, 2)}`) // Sign the transaction with the private key for the UTXO paying the fees. // Sign each token UTXO being consumed. // Generate a keypair to sign the SLP UTXO. //console.log(`slpKeyPair: ${JSON.stringify(slpKeyPair, null, 2)}`) // build tx // output rawhex //console.log(`Transaction raw hex: `) //console.log(hex)