Burn - tx

Burn 𝔉rc20 token (only for burnable 𝔉rc20)

Example of Fixes Inscription data string:

op=burn,tick=fixes,amt=100000.0

Transaction parameters:

Key
Required
FType
Description

tick

t.String

Ticker: identity of the 𝔉rc20 token

amt

t.UFix64

Amount to burn: States the amount of the 𝔉rc20 token to burn

Transaction code example:

import txBurnFRC20 from "@fixes/contracts/transactions/burn-frc20.cdc?raw";

export async function burnFRC20(
  tick: string,
  amt: number
) {
  const txid = await flow.sendTransaction(txBurnFRC20, (arg, t) => [
    arg(tick, t.String),
    arg(amt.toFixed(8), t.UFix64),
  ]);
  return txid;
}

Transaction source code

https://github.com/fixes-world/fixes/blob/main/cadence/transactions/burn-frc20.cdc
import "FlowToken"
import "FungibleToken"

import "Fixes"
import "FRC20Indexer"
import "FixesInscriptionFactory"

transaction(
    tick: String,
    amt: UFix64,
) {
    let ins: auth(Fixes.Extractable) &Fixes.Inscription
    let recipient: &{FungibleToken.Receiver}

    prepare(acct: auth(Storage, Capabilities) &Account) {
        /** ------------- Prepare the Inscription Store - Start ---------------- */
        let storePath = Fixes.getFixesStoreStoragePath()
        if acct.storage
            .borrow<auth(Fixes.Manage) &Fixes.InscriptionsStore>(from: storePath) == nil {
            acct.storage.save(<- Fixes.createInscriptionsStore(), to: storePath)
        }

        let store = acct.storage
            .borrow<auth(Fixes.Manage) &Fixes.InscriptionsStore>(from: storePath)
            ?? panic("Could not borrow a reference to the Inscriptions Store!")
        /** ------------- End -------------------------------------------------- */

        // Get a reference to the signer's stored vault
        let vaultRef = acct.storage
            .borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault)
            ?? panic("Could not borrow reference to the owner's Vault!")

        let dataStr = FixesInscriptionFactory.buildBurnFRC20(tick: tick, amt: amt)

        // estimate the required storage
        let estimatedReqValue = FixesInscriptionFactory.estimateFrc20InsribeCost(dataStr)

        // Withdraw tokens from the signer's stored vault
        let flowToReserve <- (vaultRef.withdraw(amount: estimatedReqValue) as! @FlowToken.Vault)

        // Create the Inscription first
        let newInsId = FixesInscriptionFactory.createAndStoreFrc20Inscription(dataStr, <- flowToReserve, store)

        // borrow a reference to the new Inscription
        self.ins = store.borrowInscriptionWritableRef(newInsId)
            ?? panic("Could not borrow reference to the new Inscription!")

        // reference to the recipient's receiver
        self.recipient = acct.capabilities
            .get<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)
            .borrow()
            ?? panic("Could not borrow receiver reference to the recipient's Vault")
    }

    execute {
        let indexer = FRC20Indexer.getIndexer()
        let received <- indexer.burn(ins: self.ins)

        if received.balance > 0.0 {
            // Deposit the withdrawn tokens in the recipient's receiver
            self.recipient.deposit(from: <- received)
        } else {
            destroy received
        }
    }
}

Last updated