1

I'm at the very last stage of this tutorial to make a custom pallet and have tried running Substrate frontend template in my browser. I'm using this code for TemplateModule.js, but when I try to create a new claim I get this error:

Uncaught TypeError: Cannot read properties of undefined (reading 'toString')

On the line where it says:

api.query.templateModule
      .proofs(digest, result => {
        // Our storage item returns a tuple, which is represented as an array.
        setOwner(result[0].toString()) // <--- THIS LINE GIVES ME AN ERROR
        setBlock(result[1].toNumber())
      })
      .then(unsub => {
        unsubscribe = unsub
      })

And the result is that I'm not able to create a proof of existence claim. Any idea how to fix this?

This is the result object by the way: enter image description here

2
  • Looks like result is undefined, maybe check if result is not empty ?
    – lucgerrits
    Jul 25, 2022 at 13:45
  • I've posted what my result looks like in the original question. Jul 25, 2022 at 22:08

1 Answer 1

3

The error appears because before add any claim is trying to get the owner and block from an undefined value.

It has to be checked if this value exists before trying to get the owner and the block:

if(result.value[0] && result.value[1]){
   setOwner(result.value[0].toString())
   setBlock(result.value[1].toNumber())
}

The fix has been proposed for the documentation tutorial code here

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.