I'm trying to listen for an event in my smart contract when I call another function.

Smart contract event

event documentAdded(
    uint id

Smart contract method

function sendDocument(
    string memory _ipfsLocation, 
    uint256 _uploadDate 
    documentCount ++;
    ListOfDocuments[documentCount] = documentStore(documentCount, _ipfsLocation, msg.sender, _uploadDate);
    emit documentAdded(documentCount);

React code

 var event = storehash.events.documentAdded()

        function(error, result) {
            if (!error)
                this.setState({idForBlockchain: result.args.id.toString()})

    //call the smart contract method to create a new document
    const documentId = await storehash.methods.sendDocument(this.state.IPFSlink, newDate).send({from: this.state.account})

The problem is when I run the react code it gives me the error:

event.watch is not a function

Am I using watch wrong in some way or is there a problem with how I am assigning the event to a var?

Sorry if this is basic, I'm still new enough to solidity.

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.