Introducing a command line tool for Asset Hub: polkacli

As a recent spare-time project I decided to write a tool which I could use in development workflows to support other projects.

polkacli is a straightforward cli tool for managing assets and NFTs. It allows you to mint NFTs, check balances, and send transactions directly from the terminal. for anyone looking to automate testing workflows or integrate into shell scripts, this tool might work for your needs.

why polkacli?

most nft platforms on polkadot offer browser-based interfaces, and while these are fine for what they offer, I prefer a simpler approach. this is where polkacli comes in. it’s lightweight, scriptable, and designed for developers who want to bypass uis entirely for common actions.

need to mint 100 nfts? automate it. want to check balances or send funds programmatically? no problem. I’ve found this nice for e.g. continually sending funds back and forth between accounts on testnet to check against UI development.

setup and installation

Installing polkacli requires rust. The installation process is typical:

git clone https://github.com/lovelaced/polkacli.git
cd polkacli
cargo build --release

At this point, you can configure your account. Accounts are stored using either mnemonic phrases or secret URIs, and RPC endpoints can be easily switched depending on the network you wish to connect to (e.g., assethub mainnet, testnet, etc.). I would recommend not using it with a production network yet, though! It’s meant to be more of a development tool/helper for the time being (and PAS is hardcoded as a unit currently).

configuring accounts and rpc

polkacli stores its configuration in ~/.polkacli/config. everything from your mnemonic phrase to rpc endpoint is stored in plaintext, so there are clear security implications (more on that later).

to set your account, you can use either a mnemonic or secret URI:

polkacli set-account --mnemonic "<mnemonic>"

This writes the mnemonic to your config file, which polkacli will use for signing transactions. Similarly, you can also point the cli to an RPC endpoint. the default is Paseo Asset Hub, but you can change this to anything:

polkacli set-rpc "<rpc-url>"

nft minting: json, ipfs, and automation

Where polkacli shines (imo) is its NFT minting workflow. The process uses pre-created JSON files for metadata and supports optional image pinning via IPFS (via Pinata integration). The entire NFT minting process is scriptable, so if you’re minting NFTs in bulk or as part of a larger system, this is ideal.

here’s how it works.

1. prepare your nft json

polkacli expects metadata in standard NFT json format. at a minimum, this includes an image url, name, and type. here’s an example:

{
  "animation_url": "",
  "attributes": ["rare"],
  "description": "a cool nft",
  "external_url": "https://my.nft.shop",
  "image": "",
  "name": "edition 1",
  "type": "image/jpg"
}

2. minting the nft

once you have the json prepared, minting the nft is just a matter of passing the file to the cli:

polkacli mint-nft <collection_id> <nft_id> --json nft.json --image nft.jpg

polkacli handles image pinning through IPFS (if configured with pinata), and the cli will update your json file with the correct ipfs link. if no image is provided, polkacli attempts to infer the image filename from the json filename. if nothing matches, the process will fail.

3. automation

because polkacli is built for the terminal, it lends itself to automation. a common use case might involve minting a batch of NFTs for a large collection. You can do this without using a loop since it should try to match filenames if you just give it folders as arguments to mint-collection instead.

account and transaction management

in addition to NFT minting, polkacli also handles basic account operations. this includes checking balances and sending funds. need to see how much PAS you have? run:

polkacli balance

this retrieves the balance for your configured account. similarly, sending funds is just a one-liner:

polkacli send <address> <amount>

security implications

polkacli in its current iteration is not written with high security in mind. all sensitive data - your mnemonic & pinata JWT - is stored in plaintext in ~/.polkacli/config. this is fine for dev environments, but you should avoid running this tool on shared machines or anywhere you can’t guarantee security. There is an open issue to encrypt this.

future

There are a few other issues I’ve opened in the repo for potential future features/enhancements (the biggest of which is that it currently doesn’t batch transactions and waits for each tx/mint/etc to finalize), feedback and contributions are very welcome! It’s probably a bit rough around the edges at the moment as it was just a weekend project. Hopefully someone can find this useful, and I’m also happy to hear anyone’s suggestions for its future.

17 Likes

Very interesting.

I somehow stumbled across this post after 2 hours of trying to figure out how to issue and query assets in JS or RPC.

This could definitively be helpful.

1 Like