I have read all the other answers, but it doesnt seem to really work for me. At first I thought it worked but then I noticed it didnt. What is the best way to retrieve the value of the last event that happened. Sample code:

import { React, useState, useEffect } from "react";

const [counter, setCounter] = useState();

dex.getPastEvents('NewDeadline', {
    filter: {},
    fromBlock: 'latest',
    toBlock: 'latest'
    for(var k in events){


Of curse I could iterate throught them and get the last value of all the logs. But this doesnt seem like good practice.

2 Answers 2


Very simple answer I just figured out myself: Just do fromBlock: 0 to get all Events, and as Index just type events.length-1. In the end really simple.



fromBlock: 'latest',
toBlock: 'latest'

you can see only events from one last block. You need set fromBlock to 0 or latest-n to get more range

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.