您现在的位置:kastop>> Kas信息 Kaspa应用>>正文内容

Kasplex covers the fee of reveal tx示例

now commit output covers the fee of reveal tx。


import { RpcClient, Resolver, ScriptBuilder, Opcodes, PrivateKey, addressFromScriptPublicKey, createTransactions, kaspaToSompi } from "./wasm"


const RPC = new RpcClient({

  resolver: new Resolver(),

  networkId: 'testnet-11'

})


await RPC.connect()


const privateKey = new PrivateKey('')

const publicKey = privateKey.toPublicKey()

const address = publicKey.toAddress('testnet-11')

console.log(address.toString())


const data = { "p": "krc-20", "op": "mint", "tick": "TNACHO" }


const script = new ScriptBuilder()

  .addData(publicKey.toXOnlyPublicKey().toString())

  .addOp(Opcodes.OpCheckSig)

  .addOp(Opcodes.OpFalse)

  .addOp(Opcodes.OpIf)

  .addData(Buffer.from("kasplex"))

  .addI64(0n)

  .addData(Buffer.from(JSON.stringify(data, null, 0)))

  .addOp(Opcodes.OpEndIf)


const P2SHAddress = addressFromScriptPublicKey(script.createPayToScriptHashScript(), 'testnet-11')!


const { entries } = await RPC.getUtxosByAddresses({ addresses: [ address.toString() ] })

const { transactions } = await createTransactions({

  priorityEntries: [],

  entries,

  outputs: [{

    address: P2SHAddress.toString(),

    amount: kaspaToSompi("10")!

  }],

  changeAddress: address.toString(),

  priorityFee: kaspaToSompi("1")!,

  networkId: 'testnet-11'

})


for (const transaction of transactions) {

  transaction.sign([ privateKey ])

  const hash = await transaction.submit(RPC)


  console.log('submitted P2SH commit sequence transaction on:', hash)


  setTimeout(async () => {

    const { entries } = await RPC.getUtxosByAddresses({ addresses: [ address.toString() ] })

    const revealUTXOs = await RPC.getUtxosByAddresses({ addresses: [ P2SHAddress.toString() ] })


    const { transactions } = await createTransactions({

      priorityEntries: [ revealUTXOs.entries[0] ],

      entries,

      outputs: [],

      changeAddress: address.toString(),

      priorityFee: kaspaToSompi("1")!,

      networkId: 'testnet-11'

    })


    for (const transaction of transactions) {

      transaction.sign([ privateKey ], false)


      let ourOutput = transaction.transaction.inputs.findIndex((input) => input.signatureScript === '')


      if (ourOutput !== -1) {

        const signature = transaction.signInput(ourOutput, privateKey)

        transaction.fillInput(ourOutput, script.encodePayToScriptHashSignatureScript(signature))  

      }


      console.log('Submitted reveal tx sequence transaction:', await transaction.submit(RPC))

    }

  }, 20000)

}



感动 同情 无聊 愤怒 搞笑 难过 高兴 路过
【字体: 】【收藏】【打印文章】 【 打赏 】 【查看评论

相关文章

    没有相关内容