Skip to content

A helpful bot for tracking your Solana NFT project on discord channels.

License

Notifications You must be signed in to change notification settings

milktoastlab/SolanaNFTBot

Repository files navigation

Solana NFT Bot

Solana NFT bot is a helpful bot for your Solana NFT projects.

Sponsor

This project is proudly sponsored by milktoast.world: An NFT project that aims to spread happiness and cheer.

If you find this project useful, please support us by following Milktoast and KryptoJ on Twitter!

Features

  • Notify discord channel on each purchase in marketplaces.
  • Send Twitter tweet on each purchase in marketplaces. (Experimental)
  • Support major marketplaces

Screen Shot 2022-01-30 at 10 34 53 pm

Running using docker

Requirement

  • Docker >= v20.10
    • If you're new to Docker, we recommend going through their get started page to gain a basic understanding of Docker before moving forward.
  • A Solana RPC node/server - This is needed so the bot know where to call to fetch solana transactions. Here are some potential routes to get a node:

Instructions

Run bot locally using docker in the terminal

If you're new to docker, before starting I recommend

Run the following command with your own secrets replaced with your own configuration:

docker run --name nftbot -d -p 4000:4000 -e SOLANA_RPC=YOURRPCURL -e DISCORD_BOT_TOKEN=YOURDISCORDTOKEN -e SUBSCRIPTION_DISCORD_CHANNEL_ID=YOURCHANNELID -e SUBSCRIPTION_MINT_ADDRESS=YOURMINTADDRESS milktoastlab/solananftbot

Note: The command above is tested in linux/unix env only. You may have a different experience in Windows. Please check the documentation on how to run docker command in windows if you need any help.

View logs

docker logs ntfbot

To make sure the bot is working properly, use /test-sale-tx endpoint

curl "http://localhost:4000/test-sale-tx?signature={sale_transaction_signature}&channelId={discord_channel_id}"

In case of DiscordAPIError: Missing Access error, check if the bot has been invited to the channel. Go to the channel, click "Add members or roles" and add your bot account as a member.

Alternatively, you can run it using docker-compose:

Update .env with your secret and run

docker-compose up -d bot

See here for more details on environment variables

View logs

docker-compose logs bot

Running in development

Requirement

  • Node >= 16.6
  • Yarn

Instructions

1. Install dependencies

yarn install

2. Update .env with your secrets

Follow the instructions here

3. Run the server

yarn dev

Configurable environments

Here are a list of environments you need to configure before running the NFT bot.

# RPC node url
SOLANA_RPC=
# Discord bot secret
DISCORD_BOT_TOKEN=
# The discord channel to notify
SUBSCRIPTION_DISCORD_CHANNEL_ID=
# Mint address to watch for sales
SUBSCRIPTION_MINT_ADDRESS=
# Twitter secrets
TWITTER_API_KEY=
TWITTER_API_KEY_SECRET=
TWITTER_ACCESS_TOKEN=
TWITTER_ACCESS_TOKEN_SECRET=
# Magic eden API
MAGIC_EDEN_URL=https://api-mainnet.magiceden.dev/v2
# Enter the NFT collection that you want to track
MAGIC_EDEN_COLLECTION=
# The discord channel to notify
MAGIC_EDEN_DISCORD_CHANNEL_ID=

https://github.com/milktoastlab/SolanaNFTBot/blob/main/.env

Variable breakdowns

DISCORD_BOT_TOKEN

This is your discord bot secret. If you don't have a discord bot yet, you can create one following the instructions here: https://discordpy.readthedocs.io/en/stable/discord.html

Make sure your bot has the required permissions:

  • View channels
  • Read/Send messages
  • Send messages
  • Embed links

Screen Shot 2021-10-31 at 9 25 31 am

SUBSCRIPTION_DISCORD_CHANNEL_ID

This is the ID of the discord channel you want to send notifications to. You will need to enable developer mode have access the channel IDs. Here are the instructions: https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-

SUBSCRIPTION_MINT_ADDRESS

This is the address that you want the Solana NFT bot to watch for notifications. It needs to be one of the creator addresses: Screen Shot 2021-11-12 at 6 16 31 pm

Note: Avoid personal addresses because it could detect unwanted sales.

Watch multiple addresses

You can watch multiple addresses at once by using a comma between addresses:

SUBSCRIPTION_MINT_ADDRESS=add123,add1235

This feature reduces the need to run multiple containers in production.

Twitter variables

Experimental: We haven't stress test Twitter notification on high volume projects. We recommend you have a good internet connection for your bot if you want to use this feature, because for each notification, the bot will upload the nft image to Twitter for display. Create a Github issue to let us know if you encounter any problems.

To post sales notification tweets to Twitter via the API, you will first need Elevated access to the Twitter API.

While logged in to the account you want to use the Twitter API for, apply for Elevated access to the twitter API by clicking the link here and following the steps: https://developer.twitter.com/en/portal/petition/essential/basic-info

The approval process may take a while.

Create a new project, and create a new App under that project.

The API Key and secret will be displayed to you there, which you'll assign to TWITTER_API_KEY and TWITTER_API_KEY_SECRET respectively.

Then, click on the Keys and tokens tab, and generate the Access Token and Secret. Assign these to TWITTER_ACCESS_TOKEN and TWITTER_ACCESS_TOKEN_SECRET respectively.

Magic Eden variables

Magic eden's NFT trading program has changed to V2, which means the old way of detecting sales won't work anymore. We have updated the bot to use the new API to detect sales.
To enable this feature, you will need to add the following variables to your .env file:

MAGIC_EDEN_COLLECTION

This is the collection key to magic eden. To find our what it is, navigate to the collection page and look at the url. It should be the last part of the url.

Example:
https://magiceden.io/marketplace/milktoast

The collection key is "milktoast"

MAGIC_EDEN_DISCORD_CHANNEL_ID

This is the discord channel to notify. Same as SUBSCRIPTION_DISCORD_CHANNEL_ID but it doesn't support multiple channels at the moment.

Production deployment

The solana nft bot is containerized, you can deploy it on any hosting service that supports docker.

Here are some options:

Marketplace support

Adding new marketplace

SolanaNFTBot aim to support as many marketplaces are possible. Here is the instruction on how you can add support to other marketplaces.

1. Add a new marketplace config

Use src/lib/marketplaces/solsea.ts as example

2. Write a test for the marketplace

Use src/lib/marketplaces/solsea.test.ts as example

3. Add the new marketplace to the existing list

src/lib/marketplaces/marketplaces.ts

Support

If you have any questions or feedback, feel free to jump into our discord #dev-talk channel and have a chat. https://discord.com/invite/GYxur2tvzP