USER
this is the all script, this script work with all tokens which one have in coingecko, but i add this new tokens and now in terminal i see messages wich i sent last one, everytime 0 usd
const axios = require('axios');
const Web3 = require('web3');
const BN = require('bn.js');
// Ethereum RPC endpoint
const ethereumRpcUrl = 'https://mainnet.gateway.tenderly.co';
const web3 = new Web3(new Web3.providers.HttpProvider(ethereumRpcUrl));
// Token configurations and your Telegram bot token and chat ID
const tokens = [
{
name: 'VIVEK',
contractAddress: '0x0C04fF41b11065EEd8c9EDA4d461BA6611591395', // TRUTH token contract address
decimals: 9,
coingeckoId: 'TRUTH',
volumeThreshold: new BN('5000'), // 5000 USD threshold
priceUsd: new BN(0.020) // Placeholder for TRUTH price in USD
},
{
name: 'blur',
contractAddress: '0x23D17de53aae4A767499A9d8b8C33b5b1C3ebdb0', // XRP token contract address
decimals: 18,
coingeckoId: 'BLUR',
volumeThreshold: new BN('200'), // 200 USD threshold
priceUsd: new BN(0.0000033) // Placeholder for BLUR price in USD
},
{
name: 'Flappy',
contractAddress: '0x590246Bfbf89b113D8ac36FaEeA12B7589f7FE5b', // ARB token contract address
decimals: 9,
coingeckoId: 'FLAPPY',
volumeThreshold: new BN('10000'), // 10,000 USD threshold
priceUsd: new BN(0.0000066) // Placeholder for Flappy price in USD
},
{
name: 'Draggy',
contractAddress: '0xd12A99dbC40036CEc6f1b776dccd2d36f5953B94', // SHIBA token contract address
decimals: 9,
coingeckoId: 'DRAGGY',
volumeThreshold: new BN('2000'), // 2000 USD threshold
priceUsd: new BN(0.000000003) // Placeholder for DRAGGY price in USD
}
];
const telegramBotToken = ''; // Your Telegram bot token
const telegramChatId = ''; // Your Telegram chat ID
const volumeThreshold = 100000; // 100,000 USD threshold
const timeWindow = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
// ERC20 Token Contract ABI (example ERC20 standard ABI)
const erc20Abi = [
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_spender",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "balanceOf",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
},
{
"name": "",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"name": "_initialSupply",
"type": "uint256"
},
{
"name": "_name",
"type": "string"
},
{
"name": "_symbol",
"type": "string"
},
{
"name": "_decimals",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "owner",
"type": "address"
},
{
"indexed": true,
"name": "spender",
"type": "address"
},
{
"indexed": false,
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "from",
"type": "address"
},
{
"indexed": true,
"name": "to",
"type": "address"
},
{
"indexed": false,
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
}
];
let buyVolumes = tokens.map(token => ({
name: token.name,
volumes: [],
lastNotificationTime: 0
}));
let lastProcessedBlock = 0;
async function fetchTokenPrices() {
try {
const ids = tokens.map(token => token.coingeckoId).join(',');
const response = await axios.get(`https://api.coingecko.com/api/v3/simple/price?ids=${ids}&vs_currencies=usd`);
tokens.forEach(token => {
const price = response.data[token.coingeckoId]?.usd;
if (price) {
// Convert to BN with 18 decimal places (assuming a fixed-point format)
token.priceUsd = new BN(Math.floor(price * 1e18).toString());
} else {
token.priceUsd = new BN(0); // Default to 0 if the fetch fails
}
console.log(`Fetched price for ${token.name}: ${token.priceUsd.toString()}`);
});
} catch (error) {
console.error('Error fetching token prices:', error);
tokens.forEach(token => {
token.priceUsd = new BN(0); // Default to 0 if the fetch fails
});
}
}
function calculateTotal24HourVolume(tokenName) {
const currentTime = Date.now();
const tokenVolume = buyVolumes.find(volume => volume.name === tokenName);
tokenVolume.volumes = tokenVolume.volumes.filter(vol => currentTime - vol.time <= timeWindow);
const totalVolume = tokenVolume.volumes.reduce((sum, vol) => sum.add(vol.value), new BN(0));
console.log(`Token: ${tokenName}, Volumes: ${tokenVolume.volumes.map(v => v.value.toString())}, Total Volume: ${totalVolume.toString()}`);
return totalVolume;
}
async function getBlockWithRetry(blockNumber) {
const maxRetries = 5;
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await web3.eth.getBlock(blockNumber, true);
} catch (error) {
if (attempt === maxRetries) {
throw error;
}
console.error(`Error fetching block ${blockNumber}, attempt ${attempt}:`, error);
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
}
}
}
async function processBlock(blockNumber) {
try {
const block = await getBlockWithRetry(blockNumber);
let newTransfers = [];
for (const tx of block.transactions) {
for (const token of tokens) {
if (tx.to && tx.to.toLowerCase() === token.contractAddress.toLowerCase()) {
try {
const decodedInput = web3.eth.abi.decodeParameters(['address', 'uint256'], tx.input.slice(10));
const tokenAmount = new BN(decodedInput[1]);
const usdValue = tokenAmount.mul(token.priceUsd).div(new BN(10).pow(new BN(token.decimals + 18)));
console.log(`Decoded input for ${token.name}: ${decodedInput[1]}`);
console.log(`Token amount for ${token.name}: ${tokenAmount.toString()}`);
console.log(`USD value for ${token.name}: ${usdValue.toString()}`);
if (usdValue.isZero() || usdValue.gt(new BN('1000000000'))) {
console.warn(`Ignoring suspicious transaction with value: ${usdValue.toString()}`);
continue;
}
const currentTime = Date.now();
const tokenVolume = buyVolumes.find(volume => volume.name === token.name);
tokenVolume.volumes.push({ time: currentTime, value: usdValue });
newTransfers.push({ tokenName: token.name, usdValue: usdValue.toString() });
} catch (error) {
console.error(`Error processing transaction in block ${blockNumber} for ${token.name}:`, error);
}
}
}
}
// Logging new transfers after processing all transactions in the block
for (const transfer of newTransfers) {
console.log(`New transfer in block ${blockNumber} for ${transfer.tokenName}: ${transfer.usdValue} USD`);
}
// Calculating and logging total volume after processing the block
for (const token of tokens) {
const total24HourVolume = calculateTotal24HourVolume(token.name);
console.log(`Total 24-hour volume for ${token.name}: ${total24HourVolume.toString()} USD`);
const tokenVolume = buyVolumes.find(volume => volume.name === token.name);
const currentTime = Date.now();
if (total24HourVolume.gte(token.volumeThreshold) && currentTime - tokenVolume.lastNotificationTime > timeWindow) {
await sendTelegramNotification(`🚀 24-hour volume threshold reached for ${token.name}: ${total24HourVolume.toString()} USD 🚀`);
tokenVolume.lastNotificationTime = currentTime;
}
}
} catch (error) {
console.error(`Error processing block ${blockNumber}:`, error);
}
}
async function sendTelegramNotification(message) {
const telegramApiUrl = `https://api.telegram.org/bot${telegramBotToken}/sendMessage`;
try {
const response = await axios.post(telegramApiUrl, {
chat_id: telegramChatId,
text: message,
});
console.log('Notification sent to Telegram. Response:', response.data);
} catch (error) {
console.error('Error sending notification to Telegram:', error);
if (error.response) {
console.error('Telegram API response:', error.response.data);
}
}
}
async function monitorBlocks() {
try {
const latestBlock = await web3.eth.getBlockNumber();
if (lastProcessedBlock === 0) {
lastProcessedBlock = latestBlock - 1; // Start from the previous block
}
for (let i = lastProcessedBlock + 1; i <= latestBlock; i++) {
await processBlock(i);
lastProcessedBlock = i;
}
} catch (error) {
console.error('Error in monitorBlocks:', error);
}
// Schedule the next check
setTimeout(monitorBlocks, 3000); // Check every 3 seconds
}
// Start monitoring
(async () => {
await fetchTokenPrices();
monitorBlocks();
})();
// Keep the Node.js process running
setInterval(() => {
console.log('Script is still running...');
}, 60000);
process.on('uncaughtException', (error) => {
console.error('Uncaught Exception:', error);
});
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
});