This program connects to the Ethereum mainnet and listens for Transfer events from a specific address only. It prints the event details when such an event happens.
const Web3 = require('web3');
const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');
const abi = [
{
"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"
}
];
const contractAddress = '0xYourTokenContractAddress';
const contractInstance = new web3.eth.Contract(abi, contractAddress);
// Listen only to Transfer events where 'from' is a specific address
contractInstance.events.Transfer({ filter: { from: '0x1234567890abcdef1234567890abcdef12345678' }, fromBlock: 'latest' })
.on('data', event => {
console.log('Filtered Transfer event:', event.returnValues);
})
.on('error', console.error);