0

Despite assuring that all event subscriptions are done through a websocket web3 provider instead of https, I still cannot get an event to return an info with " .on('data' ", however " .on('connected' " does return info.

Additionally calls to allEvents and getPastEvents do not return any information.

If anyone can see anything wrong with this configuration or can point me in the direction of finding the solution to this issue it would be greatly appreciated! I've been stuck on this issue for 3 days now with little progress.

Smart contract:

event ItemListed(uint256 listingId, address wallet, bool listed);

function putUpForSale(uint256 _nftId, uint256 _price, uint256 _royalty, uint256 _endTime, bool _isVEXT, bool _isVNFT) public {
        ***
        emit ItemListed(_listingId, saleListing.owner, true);
    }

truffle-config.js:

ropsten: {
      provider: () => new HDWalletProvider(mnemonic, `wss://ropsten.infura.io/ws/v3/projectID`),
      network_id: 3,       // Ropsten's id
      gas: 7976590,        // Ropsten has a lower block limit than mainnet
      //confirmations: 2,    // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 400,  // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: true,     // Skip dry run before migrations? (default: false for public nets )
      networkCheckTimeout: 1000000
    },

getWeb3Socket() code:

export const getWeb3Socket = (web3) => new Promise( async (resolve, reject) => {
    try {
        let web3Socket = web3;
        const networkName = await web3.eth.net.getNetworkType();
        alert(networkName === "ropsten");
        if(networkName === "ropsten") {
            web3Socket = new Web3(new Web3.providers.WebsocketProvider("wss://ropsten.infura.io/ws/v3/projectID"));
        }
        resolve(web3Socket);
    }
    catch(error) {
        reject(error);
    }
});

Event subscribe with web3:

const veContractAddress = config.dev_contract_addresses.ve_contract;
            const web3Socket = await getWeb3Socket(web3);
            let veABI = new web3Socket.eth.Contract(veJSON['abi'], veContractAddress);

            //console.log(veABI.events);
            await veABI.events.ItemListed({fromBlock: 0}).on('data', async function(event) {
                setEventData(event.returnValues);
                // Do something here
                alert("event fired");
            }).on('err', console.error);
2
  • can you give us the ropsten contract address?
    – Arsen
    Oct 22 '21 at 20:29
  • Ropsten address is: 0x1794455224a6426006a951a04C878C0A3406163B Oct 23 '21 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.