Building a NFT minting bot with Cardano, Telegram, and Python - Introduction

An introduction to the blog series.

An introduction to the blog series.

Introduction

After my previous posts [here, and here] on creating tokens on Cardano I received a bunch of questions on how to automate the tasks.  I started to build out a web app with Flask to do that, but saw a few projects that were better and decided to just pivot to a IPFS Pinner site. (Mr. Pinner was the result)

If you wanted a NFT web app, here are a few that look promising.

I can not vouch for any, I just know they are there.

So, I was thinking to myself what would be another fun way to create tokens?  Even though I know that in the future Daedalus will have the functionality built it, I wanted to answer that age old question "Can I build that?".  So, something that I've been wanting to build out for a while is a Telegram bot with Python.

"Can I build that?" - EPHERGENT

So here we are.  I will be building a telegram bot over the next few posts that will take a photo, upload it to IPFS and pin it, gather some token metadata from the user, ask for payment in ADA, search for UTXOs on the bot's address, mint the token and send it back to the user with some change from the minting fee.

I will be using the python-telegram-bot framework as during my research I found that OpsDroid does not have a way to get photos from the Telegram bot API currently according to the OpsDroid docs.

I've taken some time over the last two weeks to build something, you can find the finished code here on my GitHub:

GitHub - ephergent/cnft_testnet_bot
Contribute to ephergent/cnft_testnet_bot development by creating an account on GitHub.

External things needed before starting

 - A Telegram account and the desktop app
 - A BlockFrost.io account for IPFS pinning and Cardano transaction search
 - Daedalus wallet installed for the TESTNET
 	- Testnet ADA for token fees
 - Python 3.9.4 for code
 - Some good coffee

The NFT bot process

Here is a rough outline of what the app will be doing:

 - Ask for image to be uploaded using the PHOTO upload in the Telegram client

 - Take the image, upload and pin to IPFS on Blockfrost.io

 - Bot will respond with IPFS hash as link

 - Bot will Ask for NFT details for metadata (Ticker, Name, Description, etc etc)

 - Bot will use `token_utils.py` to build policies, create a wallet address, build metadata json file, get current slotNumber

 - Bot will generate and respond with ADA address to send funds to.
 	- Asking for 5 ADA minimum

 - Once user confirms to send the transaction the user will kick off minting process

 - Bot will watch the address for UTXOs to burn

 - Once funds are verified, the bot will search for the originating address to send the token back to along with the change left over.

 - The bot will then mint the token and send back to original address

 - The bot will close the chat session

OK, with out any further introduction, let's get started.

Part 1: Building a simple bot with Python 3