DEV Community

Golden Alien
Golden Alien

Posted on

🛠️ solana_discord_notifier: Watches Solana wallet, pings Discord on new tx

Solana Discord Notifier

Overview

Watches a Solana wallet address and sends a Discord ping on new transactions.

Usage

  1. Set up a Discord webhook
  2. Install required libraries: pip install solana discord.py
  3. Configure the script with your Solana wallet address and Discord webhook URL ## Configuration
  4. Set SOLANA_WALLET_ADDRESS environment variable to your Solana wallet address
  5. Set DISCORD_WEBHOOK_URL environment variable to your Discord webhook URL
import os
import json
import requests
import time
from solana.rpc.api import Client
import discord
from discord.webhook import AsyncWebhookAdapter
import aiohttp
import asyncio

SOLANA_WALLET_ADDRESS = os.environ['SOLANA_WALLET_ADDRESS']
DISCORD_WEBHOOK_URL = os.environ['DISCORD_WEBHOOK_URL']

async def send_notification(transaction):
    async with aiohttp.ClientSession() as session:
        webhook = AsyncWebhookAdapter(session)
        embed = discord.Embed(title='New Transaction', description=transaction)
        await webhook.send_webhook(url=DISCORD_WEBHOOK_URL, embed=embed)

async def main():
    client = Client('https://api.devnet.solana.com')
    last_transaction = None
    while True:
        transactions = client.get_confirmed_transactions_for_address(SOLANA_WALLET_ADDRESS)
        if transactions and transactions[0] != last_transaction:
            await send_notification(transactions[0])
            last_transaction = transactions[0]
        await asyncio.sleep(60)

if __name__ == '__main__':
    import argparse
    parser = argparse.ArgumentParser(description='Solana Discord Notifier')
    args = parser.parse_args()
    asyncio.run(main())
Enter fullscreen mode Exit fullscreen mode

Top comments (0)