0

I am attempting to collect event information from a contract. When I call the event, I am attempting to collect a specific return value event.returnValue.pubkey. When I run the code below, I get the following type error TypeError: Cannot read property 'pubkey' of undefined.

Can you help me determine why this is happening

const Web3 = require('web3');

// instantiate Deposit Contract and web3 interface
const web3 = new Web3(new Web3.providers.HttpProvider("https://goerli.infura.io/v3/942365ea7fa043ac845ac1ba4aae57bc")); 
const abi = [{"name":"DepositEvent","inputs":[{"type":"bytes","name":"pubkey","indexed":false},{"type":"bytes","name":"withdrawal_credentials","indexed":false},{"type":"bytes","name":"amount","indexed":false},{"type":"bytes","name":"signature","indexed":false},{"type":"bytes","name":"index","indexed":false}],"anonymous":false,"type":"event"},{"outputs":[],"inputs":[{"type":"address","name":"_drain_address"}],"constant":false,"payable":false,"type":"constructor"},{"name":"get_deposit_root","outputs":[{"type":"bytes32","name":"out"}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":95389},{"name":"get_deposit_count","outputs":[{"type":"bytes","name":"out"}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":17683},{"name":"deposit","outputs":[],"inputs":[{"type":"bytes","name":"pubkey"},{"type":"bytes","name":"withdrawal_credentials"},{"type":"bytes","name":"signature"},{"type":"bytes32","name":"deposit_data_root"}],"constant":false,"payable":true,"type":"function","gas":1754607},{"name":"drain","outputs":[],"inputs":[],"constant":false,"payable":false,"type":"function","gas":35793},{"name":"drain_address","outputs":[{"type":"address","name":"out"}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":663}];
const address = '0x0F0F0fc0530007361933EaB5DB97d09aCDD6C1c8';
const depositContract = new web3.eth.Contract(abi, address);


//helper function + instantiating variables
const first_block = 2845084
let unique_addresses = [];
let validatorcountperidentity = {};

let getEventProperty = async (block_start, block_end) => {
    
    let events;
    await depositContract.getPastEvents('DepositEvent', {fromBlock: block_start, toBlock: block_end})
        .then(results => { events = results });

    for (event of events) {

        if (!(event.returnValue.pubkey in unique_addresses)) {
            unique_addresses.push(event.returnValue.pubkey)

            // validatorcountperidentity[] 
        } 
    }
}

getEventProperty(first_block, first_block);

1 Answer 1

2

Change event.returnValue to event.returnValues and you should be able to access your event data. If still cannot access them start by debugging results.

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.