0

I would like to know how to pull the account value from returnValues: Result {} of this web3.eth.Contract

This code logs to the console just fine, but I have scoured documentation on objects and on web3js to find ways to transform this object to no avail. I have also tried filtering and topics per https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#id48 but have had no luck...

enter image description here

for (const element2 of lendingPairList) {
                  const eventPair = new web3.eth.Contract(PairContractABI, element2)
                        eventPair.getPastEvents("Deposit", {                          
                          fromBlock: 12867493,
                          toBlock: 'latest'
                      })
                      .then(events => console.log(events))
              .catch((err) => console.error(err));
                    }
                  }}      
                )}
              }
            )
          })
        }}
0

First of all events should be array of past event objects. So if you want to access the account value you should do it like this:

.then(function(events) {
    if (events.length) {
        for (var i = 0, len = events.length; i < len; i+=1) {
            console.log(events[i].returnValues.account);
        }
    }
});
2
  • This is exactly what I was looking for. Thank you so much. Aug 19 at 10:12
  • Great, you can accept my answer with the green check so others having the same issue can recognize the solution. Aug 19 at 13:21

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.