This guide introduces the key steps required to get a basic Twitter bot up and running, powered by on-chain data. This can provide the basis for building anything; from bots that tweet when particular NFTs in a collection are sold to displaying running leaderboards for web3 games. We’ll explore other fun projects in our Building with Transpose series soon, stay tuned!
Automated posting to Twitter can be a great way to maintain and build engagement for a community. NFT projects, DAOs, and protocols can all benefit from targeted tweets that keep the community up-to-date and engaged. This post will run through the steps required to get set up with a developer account on Twitter and build a simple bot that regularly tweets about ENS expiration activity using data obtained from the Transpose API.
Check out the bot live here
And the full code here
This code contains the sample we use to run our ENS bot and has a flexible system for adding additional bots. We will run through all the required steps to get your own bot up and running.
For the sake of brevity, this post will focus on the steps that come after getting a developer account ready on Twitter. You can check out guides like https://blog.hubspot.com/website/how-to-make-a-twitter-bot for an in-depth review of the process.
In brief:
Transpose will make getting the data we need for our bot incredibly simple. Getting set up with a free key on Transpose is very quick.
This will bring you to your new team’s dashboard. Note down your API key.
ENS names are readable names ending in .eth that can be used interchangeably with wallet addresses. ENS names are often treated as people’s web3 usernames, so short, readable names are in very high demand. You register names for a period of time, and great names expire as some people don’t renew their registration. When names expire, they have an associated “penalty price” that halves every day, to give the previous owner a chance to re-register.
Our bot will search through recently expired names and tweet short ones as they approach reasonable penalties.
Time to get to the actual code! Our tweet bot repo handles automatic periodic updates that let you easily pull relevant information and decide what to post. Posts are cached to make sure the bot doesn’t tweet the same thing twice.
Let’s walk through how it works!
All bot implementations start by inheriting the AbstractBot class. This simplifies interacting with the Transpose SDK and automates ensuring the bot doesn’t tweet the same thing twice.
The init function defines the data we want to tweet about, in this case, the time since expiration for ENS names. We pass in the intervals we want to tweet at (time since expiration) as well as the corresponding messages to keep things modular. The name will automatically get set to the name of the file when the bot is initialized.
In the function, we first call the super().init(name) to initialize core bot functionality, then retrieve previous tweets to make sure we don’t double-tweet even if the bot has to restart.
Finally, we set up a couple of simple data structures to store tweets in memory.
The update function gets called for every bot instance found in main.py. This is where we define what data the bot will pull and how it will decide whether or not to tweet.
In this code, we:
Picking interesting names isn’t necessarily trivial. Initially, the bot just pulled all expiring names shorter than 5 characters but we recently added a library that lets us also include common English words. We’ll leave the decision up to you, but the full code is available in the tweet bot GitHub repo.
This guide introduces the key steps required to get a basic Twitter bot up and running, powered by on-chain data. This can provide the basis for building anything from a bot that tweets when particular NFTs in a collection are sold to leaderboards for web3 games. We’ll explore other fun projects in our build with Transpose series soon, stay tuned!