Mint(batch) - tx
Mint πrc20 token
Example of Fixes Inscription data string:
op=mint,tick=fixes,amt=1000.0
Transaction parameters:
Key
Required
FType
Description
tick
t.String
Ticker: identity of the πrc20 token
amt
t.UFix64
Amount to mint: States the amount of the πrc20 token to mint. Has to be less or equal to "limit"
repeats
t.UInt64
How many times to repeat the mint action. Better less than or equal to 100 times.
Transaction code example:
import txBatchMintFRC20 from "@fixes/contracts/transactions/batch-mint-frc20.cdc?raw";
import txMintFRC20 from "@fixes/contracts/transactions/mint-frc20.cdc?raw";
async function mint(
tick: string,
amt: number,
repeats: number = 1
) {
let txid: string;
if (repeats > 1) {
txid = await flow.sendTransaction(txBatchMintFRC20, (arg, t) => [
arg(tick, t.String),
arg(amt.toFixed(8), t.UFix64),
arg(repeats, t.UInt64),
]);
} else {
txid = await flow.sendTransaction(txMintFRC20, (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/batch-mint-frc20.cdc
import "FungibleToken"
import "FlowToken"
import "FRC20Indexer"
import "Fixes"
import "FixesInscriptionFactory"
transaction(
tick: String,
amt: UFix64,
repeats: UInt64
) {
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!")
// Get a reference to the Fixes Indexer
let indexer = FRC20Indexer.getIndexer()
let tokenMeta = indexer.getTokenMeta(tick: tick)
assert(tokenMeta != nil, message: "TokenMeta for tick ".concat(tick).concat(" does not exist!"))
let insDataStr = FixesInscriptionFactory.buildMintFRC20(tick: tick, amt: amt)
var i = 0 as UInt64
while i < repeats {
i = i + 1
let tokenMeta = indexer.getTokenMeta(tick: tick)
if tokenMeta!.max == tokenMeta!.supplied {
break
}
// estimate the required storage
let estimatedReqValue = FixesInscriptionFactory.estimateFrc20InsribeCost(insDataStr)
// get reserved cost
let flowToReserve <- (vaultRef.withdraw(amount: estimatedReqValue) as! @FlowToken.Vault)
// Create the Inscription first
let newInsId = FixesInscriptionFactory.createAndStoreFrc20Inscription(
insDataStr,
<- flowToReserve,
store
)
// borrow a reference to the new Inscription
let insRef = store.borrowInscriptionWritableRef(newInsId)
?? panic("Could not borrow a reference to the newly created Inscription!")
/// Mint the FRC20 token
indexer.mint(ins: insRef)
}
}
}
Or mint simple inscription
https://github.com/fixes-world/fixes/blob/main/cadence/transactions/mint-frc20.cdc
Related docs
Last updated