0

I am trying to make a program that, given a ERC721 contract address, will listen to all transfer events done on this contract until a certain point. I am not yet very familiar with how Ethereum works, but here is what I've done so far:

abi:

abigen!(
ERC721,
r#"[
        event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)
    ]"#
);

Event building:

    let events = Contract::event_of_type::<TransferFilter>(client)
    .from_block(BlockNumber::Number(17187607.into()));

Stream building:

    let mut stream = events
    .stream_with_meta()
    .await
    .map_err(|_| "[ERROR] Invalid event stream")?
    .take(1);

And the the listener:

let event_timeout = Duration::from_secs(5);
let loop_timeout = Duration::from_secs(10);
let start = Instant::now();

while Instant::now().duration_since(start) <= loop_timeout {
    let next_event = timeout(event_timeout, stream.next());
    match next_event.await {
        Ok(Some(Ok((evt, meta)))) => {
            let from = evt.from;
            let to = evt.to;
            let zero_address = H160::from_low_u64_be(0);
            #[cfg(debug_assertions)]
            {
                println!("----------------New Event----------------");
                println!("From: {:?}", from);
                println!("To: {:?}", to);
                println!("blocknumber: {:?}", meta.block_number);
                println!("tx hash: {:?}", meta.transaction_hash);
            }
            // ... rest of the code 
        }
        Ok(Some(Err(err))) => {
            eprintln!("Error in event stream: {:?}", err);
        }
        Ok(None) | Err(_) => {
            println!("No events found");
            break;
        }
    }
}

This issue is that when testing, I get to the listener, and then nothing but a timeout, it's not fetching any event. My guess is that I didn't correctly used the abigen! macro ? I also tried to use with this JSON, but same result: [ { "anonymous": false, "inputs": [ { "indexed": true, "name": "from", "type": "address" }, { "indexed": true, "name": "to", "type": "address" }, { "indexed": true, "name": "tokenId", "type": "uint256" } ], "name": "Transfer", "type": "event" } ]

notes:

  • I'm using ehters.rs v2.0.3
  • I'm kinda trying to replicate a mix between this and this
  • I would be really happy to get the solution, but even more to learn how it works 🙏

0

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.