Twitter/X Bot Development for Crypto Project
Twitter/X remains the primary platform for crypto community — alpha spreads here faster than anywhere else. Bots are needed for specific tasks: automatic announcements of on-chain events (large transfers, liquidations, governance votes), mention monitoring, protocol metrics publishing by schedule. Telegram bots are simpler to implement, but Twitter/X — it's public visibility and narrative.
Twitter API v2: Current State
Since 2023 Twitter/X dramatically changed API conditions. Important to understand current situation before starting:
Free tier — read-only (1500 tweets/month for write, extremely limited). Essentially useless for active bot.
Basic tier ($100/month) — 3000 tweets/month write, 10K read. Sufficient for bots with moderate activity.
Pro tier ($5000/month) — 300K tweets. For high-frequency alert bots.
For most crypto projects Basic is enough. When planning bot, calculate monthly tweet volume immediately — if you plan to tweet on every major transaction on popular protocol, that could be hundreds of tweets per day.
Bot Architecture
Component 1: On-Chain Monitor
Data source — always blockchain events, not third-party aggregators (they add latency). Use WebSocket subscription for real-time:
const { ethers } = require('ethers')
const provider = new ethers.WebSocketProvider(process.env.WSS_RPC_URL)
const AAVE_POOL = '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2'
const LIQUIDATION_TOPIC = ethers.id('LiquidationCall(address,address,address,uint256,uint256,address,bool)')
provider.on({ address: AAVE_POOL, topics: [LIQUIDATION_TOPIC] }, async (log) => {
const iface = new ethers.Interface(AAVE_POOL_ABI)
const decoded = iface.parseLog(log)
const collateralAsset = decoded.args.collateralAsset
const debtAsset = decoded.args.debtAsset
const liquidatedCollateralAmount = decoded.args.liquidatedCollateralAmount
// Get USD value via Chainlink or Coingecko
const usdValue = await getUSDValue(collateralAsset, liquidatedCollateralAmount)
if (usdValue > MINIMUM_NOTABLE_USD) {
await postLiquidationTweet({ collateralAsset, debtAsset, usdValue, txHash: log.transactionHash })
}
})
Component 2: Formatting and Publishing
const { TwitterApi } = require('twitter-api-v2')
const client = new TwitterApi({
appKey: process.env.TWITTER_APP_KEY,
appSecret: process.env.TWITTER_APP_SECRET,
accessToken: process.env.TWITTER_ACCESS_TOKEN,
accessSecret: process.env.TWITTER_ACCESS_SECRET,
})
const rwClient = client.readWrite
async function postLiquidationTweet({ collateralAsset, debtAsset, usdValue, txHash }) {
const collSymbol = await getTokenSymbol(collateralAsset)
const debtSymbol = await getTokenSymbol(debtAsset)
const text = [
`🔴 AAVE Liquidation`,
``,
`Collateral: ${collSymbol}`,
`Debt: ${debtSymbol}`,
`Value: $${formatUSD(usdValue)}`,
``,
`Tx: https://etherscan.io/tx/${txHash}`,
``,
`#DeFi #AAVE #Liquidation`
].join('\n')
try {
await rwClient.v2.tweet(text)
} catch (error) {
if (error.code === 403) {
// Duplicate tweet — add timestamp or skip
logger.warn('Duplicate tweet prevented', { txHash })
} else {
throw error
}
}
}
Rate Limiting and Anti-Ban
Twitter/X actively detects anomalous behavior. Recommendations:
- Deduplication: store txHash of published events (Redis with TTL 24h) — never tweet one event twice
- Cooldown between tweets: minimum 30 seconds between publications in series
- Queue with priorities: if many events — tweet the largest, aggregate small ones in one digest tweet
- Graceful reconnect: WebSocket connections break, need exponential backoff on reconnect
// Queue with debounce for batch events
class TweetQueue {
constructor(client, maxPerHour = 20) {
this.queue = []
this.maxPerHour = maxPerHour
this.published = []
// Publish every 3 minutes (maximum 20 per hour)
setInterval(() => this.flush(), 3 * 60 * 1000)
}
async add(event) {
// Deduplication by txHash
if (this.queue.some(e => e.txHash === event.txHash)) return
this.queue.push({ ...event, addedAt: Date.now() })
// Sort by usdValue — publish most significant first
this.queue.sort((a, b) => b.usdValue - a.usdValue)
}
async flush() {
if (this.queue.length === 0) return
const toPublish = this.queue.shift()
await this.client.v2.tweet(formatTweet(toPublish))
// Throttle: don't publish more than maxPerHour
const lastHour = this.published.filter(t => Date.now() - t < 3600000)
if (lastHour.length >= this.maxPerHour) {
logger.info('Rate limit self-imposed, queuing')
return
}
this.published.push(Date.now())
}
}
Scheduled Tweets: Protocol Metrics
Besides event-driven publishing — periodic digests:
const cron = require('node-cron')
// Daily stats at 12:00 UTC
cron.schedule('0 12 * * *', async () => {
const stats = await fetchProtocolStats()
await rwClient.v2.tweet(
`📊 Daily Stats — ${new Date().toLocaleDateString('en-US', { month: 'short', day: 'numeric' })}\n\n` +
`TVL: $${formatBigNumber(stats.tvl)}\n` +
`24h Volume: $${formatBigNumber(stats.volume24h)}\n` +
`Active Users: ${stats.activeUsers.toLocaleString()}\n\n` +
`#DeFi`
)
})
Deployment
Minimal infrastructure — Docker container on VPS with persistent WebSocket connection. PM2 or systemd for auto-restart. Logging via Winston to file + optionally Telegram alerts on bot errors.
Environment variables never in code — .env file, in production — secrets manager or hosting environment variables.
What's Included
- Twitter Developer App setup and OAuth 2.0 authentication
- On-chain monitor with WebSocket subscription to needed events
- Tweet formatting with real blockchain data
- Deduplication, rate limiting, queue management
- Scheduled publications by schedule (digests, metrics)
- Deployment on VPS with process monitoring







