Skip to content

Instantly share code, notes, and snippets.

@zh
Created December 23, 2020 17:16
Show Gist options
  • Save zh/e14cca55b064e92b088d72683619f588 to your computer and use it in GitHub Desktop.
Save zh/e14cca55b064e92b088d72683619f588 to your computer and use it in GitHub Desktop.
const currentAddress = 'simpleledger: ....'
const to = 'simpleledger:....'
const balances = await bchdNetwork.getAllSlpBalancesAndUtxos(currentAddress)
const bchBalances = balances.nonSlpUtxos
let bchUtxos = []
bchBalances.forEach((j) => j.wif = wifs[currentAddress])
bchBalances.forEach((txo) => bchUtxos.push(txo))
let tokenUtxos = []
balances.slpTokenUtxos[tokenId].forEach((j) => j.wif = wifs[currentAddress])
balances.slpTokenUtxos[tokenId].forEach((txo) => tokenUtxos.push(txo))
// create burn tx raw hex
const inputUtxos = [...bchUtxos, ...tokenUtxos]
const sendAmounts = [ new BigNumber(1) ]
const tokenReceiverAddresses = [ currentAddress ]
const changeReceiverAddress = currentAddress
const burnTxHex = await bchdNetwork.txnHelpers.simpleTokenSend({
tokenId,
sendAmounts,
inputUtxos,
tokenReceiverAddresses,
changeReceiverAddress
})
// something missing here, code below needs burnUtxo.txid and burnUtxo.vout
const inputs = [ ??? ]
const genesisTxHex = bchdNetwork.txnHelpers.simpleNFT1ChildGenesis(
tokenId,
name,
ticker,
documentUri,
documentHash,
to,
currentAddress,
inputs
)
const burn = {
tokenId: Buffer.from(tokenId, 'hex'),
tokenType: 129,
amount: '1',
outpointHash: Buffer.from(Buffer.from(inputs[0].txid, 'hex').reverse()), // this line need burnUtxo.tx from inputs[0]
outputVout: inputs[0].vout // this line need burnUtxo as input[0].vout from inputs[0]
}
const genesisTxid = await bchdNetwork.sendTx(genesisTxHex, [burn])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment