0

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'
}).then(function(events){
    for(var k in events){

        console.log(events[k].returnValues["_deadline"]);
    }
});

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

0

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.

0

With

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, privacy policy and cookie policy

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