sigle / StacksNFTBot

JSON driven NFT discord/twitter bot for Blockstack NFTs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSON driven STX NFT bot

Report marketplace actions (listings, purchases, and offers) for some Blockstack NFT collection to Discord/Twitter.

Media

View sample tweet

Sample Discord embed

Description

This program will periodically query the Stacks Blockchain API to fetch NFT events for user defined NFT collections across user defined Marketplace contracts.

Getting Started

You will want to create a new repo using this project as a template.

Dependencies

  • If you want to report events to Twitter, you will need a Twitter Developer Account along with relevant API credentials.
  • If you want to report events to Discord, you will need a Discord Bot Account along with the bot token.

It may be a good idea to have at least two sets of Twitter/Discord API credentials, for local development and production deployments.

Installing

  • Create a new .env file in the root directory, following the template outlined in .env.template

Executing program

  • To run locally, use npm run start:dev. This will use nodemon to enable automatic reloading.
  • To run in a production environment, use npm start

The program will start listening for new NFT events starting at the current block height.

For local development, you may want to start listening at an earlier block so that you dont have to wait for new events.

You can do this by specifying the INITIAL_BLOCKHEIGHT environment variable. Take care that you are NOT setting this variable in any production deployment, and that you do not set it too far off from the current blockheight, otherwise the app will be overloaded with hundreds of events.

Using JSON configurations

There are two key files used for configuring the behavior of this app:

  • collections.json
    • This file contains configurations for the different NFT collections you are interested in tracking. A configiguration here is used to specify the NFT contract address and name, templates for formatting Twitter and Discord messages, and instructions on where to fetch metadata and images.
  • marketplaces.json
    • This file contains configurations for the different marketplace contracts to scan for events. A configuration here specifies how to parse a Blockstack transaction to extract necessary variables (collection contract, NFT ID, STX amount) for a given market action.

Sample configurations have been provided for a few existing STX collections and marketplaces which should help you in creating any new configuration.

Configurations use eval and mustache.js for evaluating and rendering templates.

A breakdown of the file contents can be found at collection.ts and marketplace.ts

Values which are rendered with Mustache will be marked with (mustache), and values which are evaluated with eval will be marked with (eval)

NOTE - eval expects a valid JS expression, so string values must be wrapped in 'single quotes' and the newline character must have an escaped backslash: \\n

Mustache templating

It may be worthwhile to first familiarize yourself with the mustache.js documents.

The view which is passed to all Mustache renders can be found at nft.ts, and any of these variables can be referenced in the templates.

Deploying

This is just a simple nodeJS app, so you should be able to deploy it anywhere you wish. Heroku is a good platform if you are just getting started, as you can deploy straight from a git repo.

(note: if using Heroku, make sure to use a Worker dyno, not a Web dyno)

License

This project is licensed under the GNU GENERAL PUBLIC LICENSE - see the LICENSE file for details

About

JSON driven NFT discord/twitter bot for Blockstack NFTs

License:GNU General Public License v3.0


Languages

Language:TypeScript 100.0%