I've been trying to follow the Listening to Events sample code and make a filter that detects when a specific address receives BUSD instead of DAI. However, it doesn't seem to do any filtering and logs Transfer events for other addresses as well. I used ethers version 5.5.1 to test the samples of code below.

Attempt 1

const ercTokenAddress = "0xe9e7cea3dedca5984780bafc599bd69add087d56"; // BUSD
const abi = [
  "event Transfer(address indexed from, address indexed to, uint amount)"
const contract = new Contract(ercTokenAddress, abi, provider);

// A filter for when a specific address receives tokens
let filter = contract.filters.Transfer(null, recipient)
// Receive an event when that filter occurs
contract.on(filter, (from, to, amount, event) => {
    console.log(`to: ${to}`)

Sample results:

to: 0xc2b068161D308AB9794098992Ad036B23E0B57FB
to: 0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16
to: 0xc590175E458b83680867AFD273527Ff58f74c02b
to: 0x71C292269718BC1e38EdF6023Fb427D35924389E
to: 0x5822a13D770675402707A9215215F1d5EE6646Df
to: 0x2e707261d086687470B515B320478Eb1C88D49bb
to: 0x978c47e98E038b37E4F0c0b48D08b752BaeD8469
to: 0xbAF9A5d4b0052359326A6CDAb54BABAa3a3A9643
to: 0x1B96B92314C44b159149f7E0303511fB2Fc4774f

Attempt 2

I have also tried specifying both sender and recipient addresses as in the answer to this post:

let filter = contract.filters.Transfer(sender, recipient)
contract.on(filter, (from, to, amount, event) => {
    console.log(`from: ${from} | to: ${to}`)

Sample results:

from: 0xd5c20E79D9cd9DD697526e2a41447f3ACa91f84A | to: 0xc58b4e438d338Ce31eC0C91f1aA8287A7409070A
from: 0x025C26c69B939bb4c19635146ea7106D92575556 | to: 0xC63B0d319b926CC6380164214E3E2056C76cD3D7
from: 0xc73158584A89153065F37C5a5372d51aa06e949E | to: 0x2b92C42462672A13106c0867C67E1Af22328e694
from: 0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16 | to: 0x4913b6a41D4B41DD587EBb99B11cF01fB3c3d90d
from: 0xDBAeE0c1012896758f596fE8eaAB2C8Ffa49E4fe | to: 0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16
from: 0xd76026a78a2A9aF2f9F57fe6337eED26Bfc26AED | to: 0x873F73f60756eA5Fb687627670088b4B7613C92c
from: 0xBbd923e6Ffed3A6Ed1497e8Ed4921145ff94E3db | to: 0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16
from: 0x213f7E7Fe55e59B526b5255270Fc0F665Fb36B57 | to: 0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16
from: 0x05faf555522Fa3F93959F86B41A3808666093210 | to: 0xd76026a78a2A9aF2f9F57fe6337eED26Bfc26AED
from: 0x58F876857a02D6762E0101bb5C46A8c1ED44Dc16 | to: 0xB72723e36a83FB5Fe1793f06b436F4720F5DE4F9

Could someone please explain to me what I'm doing wrong?

  • the events seems to be working or you wouldnt get anything printed, what exactly are you expecting to happen?
    – Julissa DC
    Commented Oct 25, 2021 at 13:06
  • I was expecting the filters to filter the event by the specified addresses, but they're all different. Attempt 1 should only show a single address. Attempt 2 should show the same two addresses every time.
    – vlj614
    Commented Oct 25, 2021 at 22:45


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.