SAD PANDA: TypeError: failed to fetch

382 Views Asked by At

​ === SAD PANDA ===

TypeError: Failed to fetch

=== SAD PANDA ===

While executing a flow cadence transaction in react.js, I got the above error.

My intention is when I click the minttoken button, this transaction has to execute so as to mint the NFT.

const mintToken = async() => {
        console.log(form.name)
        const encoded = await fcl.send([
             fcl.proposer(fcl.currentUser().authorization),
            fcl.payer(fcl.authz),
             fcl.authorizations([fcl.authz]),
            fcl.limit(50),
            fcl.args([
                fcl.arg(form.name,t.String),
                fcl.arg(form.velocity,t.String),
                fcl.arg(form.angle,t.String),
                fcl.arg(form.rating,t.String),
                fcl.arg(form.uri,t.String)    
              ]),
            fcl.transaction`
        import commitContract from 0xf8d6e0586b0a20c7
                
                transaction {
                let receiverRef: &{commitContract.NFTReceiver}
                let minterRef: &commitContract.NFTMinter

                prepare(acct: AuthAccount) {
                    self.receiverRef = acct.getCapability<&{commitContract.NFTReceiver}>(/public/NFTReceiver)
                        .borrow()
                        ?? panic("Could not borrow receiver reference")        
                    
                    self.minterRef = acct.borrow<&commitContract.NFTMinter>(from: /storage/NFTMinter)
                        ?? panic("could not borrow minter reference")
                }

                execute {
                    let metadata : {String : String} = {
                        "name": name,
                        "swing_velocity": velocity, 
                        "swing_angle": angle, 
                        "rating": rating,
                        "uri": uri
                    }
                    let newNFT <- self.minterRef.mintNFT()
                
                    self.receiverRef.deposit(token: <-newNFT, metadata: metadata)

                    log("NFT Minted and deposited to Account 2's Collection")
                }
                }
            
        
                `
                
      ]);
      await fcl.decode(encoded);
    }
1

There are 1 best solutions below

0
On

this error being so useless is my fault, but I can explain what is happening here because it also only happens in a really specific situation.

Sad Panda error is a catch all error that happens when there is a catastrophic failure when fcl tries to resolve the signatures and it fails in a completely unexpected way. At the time of writing this it usually shows up when people are writing their own authorization functions so that was the first thing i looked at in your code example. Since you are using fcl.authz and fcl.currentUser().authorization (both of those are the same by the way) your situation here isnt because of a custom authorization function, which leads me to believe this is either a configuration issue (fcl.authz is having a hard time doing its job correctly) or what fcl is getting back from the wallet doesn't line up with what it is expecting internally (most likely because of an out of date version of fcl).

I have also seen this come up when the version of the sdk that fcl uses doesnt line up with the version of the sdk that is there (because some people have added @onflow/sdk as well as @onflow/fcl) so would also maybe check to make sure you only have fcl in your package.json and not the sdk as well (everything you should need from the sdk should be exposed from fcl directly, meaning you shouldnt need the sdk as a direct dependency of your application)

I would first recommend making sure you are using the latest version of fcl (your code should still all work), then i would make sure you are only using fcl and not inadvertently using an older version of the sdk. If you are still getting the same error after that could you create an issue on the github so we can dedicate some resources to helping sort this out (and make it so you and others dont see this cryptic error in future versions of fcl)