Skip to content

Instantly share code, notes, and snippets.

@zh
Last active December 9, 2020 11:47
Show Gist options
  • Save zh/dee256f95a304a3c624e39b678ebc967 to your computer and use it in GitHub Desktop.
Save zh/dee256f95a304a3c624e39b678ebc967 to your computer and use it in GitHub Desktop.

Code

const fromSlpAddress = 'simpleledger:qp...'
const fromWIF = 'Kw...'
const toSlpAddress = 'simpleledger:qp...'

// Group NFT
const TOKENID = '4c689b3e716764aa76df2edd6c0ffd3932d16a826c7fca8bb28473d9f23d3329'

const BITBOX = require('bitbox-sdk').BITBOX
const { GrpcClient } = require('grpc-bchrpc-node')
const slpjs = require('slpjs')
const BigNumber = require('bignumber.js')
const bchaddr = require('bchaddrjs-slp')

const bitbox = new BITBOX({restURL: 'https://bchd.fountainhead.cash'})
const client = new GrpcClient({url: 'bchd.fountainhead.cash' })
const validator = new slpjs.BchdValidator(client, console)
const bchdNetwork = new slpjs.BchdNetwork({ BITBOX: bitbox, client, validator })

async function sendChildNFT (tokenId, to, from, fromWif) {
  try {
    const balances = await bchdNetwork.getAllSlpBalancesAndUtxos(from)

    let burnUtxo
    balances.slpTokenUtxos[tokenId].forEach(txo => {
      if (!burnUtxo && txo.slpUtxoJudgementAmount.isEqualTo(1)) {
        burnUtxo = txo
      }
    })
    // ...
    inputs = [burnUtxo, ...balances.nonSlpUtxos]
    inputs.map(txo => txo.wif = fromWIF)

    const name = 'SLPJS NFT1 Child #1'
    const ticker = 'SLPJS_CHILD_1'
    const documentUri = null
    const documentHash = null

    const genesisTxid = await bchdNetwork.simpleNFT1ChildGenesis(
      tokenId,
      name,
      ticker,
      documentUri,
      documentHash,
      to,
      bchaddr.toCashAddress(from),
      inputs,
      true // allowBurnAnyAmount
    )
    console.log('NFT1 Child GENESIS txn complete: ', genesisTxid)
  } catch (error) {
    console.error('error in sendNFT: ', error)
  }
}

sendChildNFT(TOKENID, toSlpAddress, fromSlpAddress, fromWIF)

Error message

error in sendChildNFT:  Error: 10 ABORTED: submitted transaction rejected to prevent token burn: use SlpRequiredBurn to allow burns: burn is not allowed
    at Object.exports.createStatusError (/bch/node_modules/grpc/src/common.js:91:15)
    at Object.onReceiveStatus (/bch/node_modules/grpc/src/client_interceptors.js:1209:28)
    at InterceptingListener._callNext (/bch/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/bch/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/bch/node_modules/grpc/src/client_interceptors.js:847:24) {
  code: 10,
  metadata: Metadata { _internal_repr: {}, flags: 0 },
  details: 'submitted transaction rejected to prevent token burn: use SlpRequiredBurn to allow burns: burn is not allowed'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment