CLI Tool to Mint Assets

Create a custom CLI Tool, using Deno and Fetch to connect to anvil API, taking few configurable parameters, it is possible to mint a collection using a binary with a custom implementation.

This a a very specific example, the goal is to show how flexible and versatile the Anvil API is.

This example will be entirely done into one file named index.ts

Objectives

  • Build a simple CLI tool to mint assets

  • Create a Policy (an NFT Collection)

  • Create a custom function to customize the asset metadata

  • Create 2 wallets, one for the policy and one to act as the customer

  • Submit transaction to the network

  • This is only an example showing the anvil api versatility

  • The example is built on Cardano Preprod

Dependencies

import { Buffer } from "node:buffer";
import {
  Credential,
  type Ed25519KeyHash,
  FixedTransaction,
  NativeScript,
  NativeScripts,
  PrivateKey,
  ScriptAll,
  ScriptPubkey,
  TimelockExpiry,
} from "npm:@emurgo/[email protected]";
import { parseArgs } from "jsr:@std/cli/parse-args";

Cardano Wallets

We have this utility to generate wallets: https://github.com/Cardano-Forge/cardano-wallet-cli/releases

You'll need to add some tADA to both wallets—100 should be more than enough.

Import Helper Functions

To reduce the amount of content in this guide, you only have to import all functions defined here:

https://github.com/Cardano-Forge/anvil-api/blob/main/docs/guides/utilities-functions/README.md

CLI

Parse and prepare the policy and wallets:

Collection configurations

This example requires 2 rules.

Meaning that the policy has to be signed by the wallet defined in the policy wallet path parameter AND all mutations must be done before the DateTime defined.

Create Metadata

This function is where you have to define your own data and configuration per asset.

CIP-25 enforces few fields as mandatory see here: https://cips.cardano.org/cip/CIP-25

You can also use our powerful metadata validator: https://metadraft.io

For example

The counter is used to be sure that the assetName remains unique.

TBD: Show an example output (screenshot or link to preprod url or all of them)

The transaction

Sign with the policy wallet

Sign with the customer wallet

usually done using the browser extension

Submit Transaction


Using the CLI

Dont forget to increase the counter, otherwise you will double mint.

File Content - (customer.json, policy.json, metatemplate.json)

customer.json

policy.json

metatemplate.json

The code will override the name key

Explorer

The Whole File (Deno Version)

index.ts

Last updated

Was this helpful?