walletconnect-monorepo
walletconnect-monorepo copied to clipboard
Error: Missing or invalid topic field
We are seeing a lot of errors coming from the wallet connect socket transport all the below: Error: Missing or invalid topic field
Logs:
message: "Uncaught (in promise): Error: Missing or invalid topic field↵Error: Missing or invalid topic field↵ at SocketTransport.send (https://localhost:4251/default~modules-approval-approval-module~modules-change-password-change-password-module~modules-chan~60cd62e9.js:1560:19)↵ at WalletConnect.<anonymous> (https://localhost:4251/default~modules-approval-approval-module~modules-change-password-change-password-module~modules-chan~60cd62e9.js:698:29)↵ at Generator.next (<anonymous>)↵ at fulfilled (https://localhost:4251/vendor.js:212225:58)↵ at ZoneDelegate.invoke (https://localhost:4251/polyfills.js:440:30)↵ at Object.onInvoke (https://localhost:4251/vendor.js:56946:33)↵ at ZoneDelegate.invoke (https://localhost:4251/polyfills.js:439:36)↵ at Zone.run (https://localhost:4251/polyfills.js:197:47)↵ at https://localhost:4251/polyfills.js:938:38↵ at ZoneDelegate.invokeTask (https://localhost:4251/polyfills.js:475:35)"
stackTrace: "send (webpack:///node_modules/@walletconnect/socket-transport/dist/cjs/index.js:57:)↵tslib_1.__awaiter (webpack:///node_modules/@walletconnect/core/dist/cjs/index.js:577:)↵fulfilled (webpack:///node_modules/tslib/tslib.es6.js:70:41)↵invoke (webpack:///node_modules/zone.js/dist/zone.js:396:)↵onInvoke (webpack:///node_modules/@angular/core/__ivy_ngcc__/fesm5/core.js:27815:)↵invoke (webpack:///node_modules/zone.js/dist/zone.js:395:)↵run (webpack:///node_modules/zone.js/dist/zone.js:153:)↵zone.scheduleMicroTask (webpack:///node_modules/zone.js/dist/zone.js:894:)↵invokeTask (webpack:///node_modules/zone.js/dist/zone.js:431:)↵scheduleResolveOrReject (webpack:///node_modules/zone.js/dist/zone.js:836:)↵function (webpack:///node_modules/zone.js/dist/zone.js:750:)↵rejected (webpack:///node_modules/tslib/tslib.es6.js:71:87)↵invoke (webpack:///node_modules/zone.js/dist/zone.js:396:)↵onInvoke (webpack:///node_modules/@angular/core/__ivy_ngcc__/fesm5/core.js:27815:)↵invoke (webpack:///node_modules/zone.js/dist/zone.js:395:)↵run (webpack:///node_modules/zone.js/dist/zone.js:153:)↵zone.scheduleMicroTask (webpack:///node_modules/zone.js/dist/zone.js:894:)↵invokeTask (webpack:///node_modules/zone.js/dist/zone.js:431:)↵onInvokeTask (webpack:///node_modules/@angular/core/__ivy_ngcc__/fesm5/core.js:27803:)"
Our setup looks fine so not sure why it keeps erroring. It actually keeps working and does not break but would rather not have that error emitting in the console.
Hmm this is new.. Any steps to reproduce?
So we have an angular app and i just connect on trust wallet (it happens on other wallets and sometimes just randomly) then i disconnect and it hits your .send with info:
parameter 1:
"{"data":"74eb97d6a74529a290a01b84daad84543c12009443c6999cea9e0235140f5248d5070802c0bedff68163f1df48b50cf8c84470b9ede4b6bd48591ef4b67aed28c8b6ac7524bf52b7307454abc29d81e9a82b3ae1db74090f7033cd7aea2249d8afa39332190ca9eb7369a242f1cf940f44031d56e093b4a0994d134fde4f75cd9ffb82fd89032b9fccab54e4cc2cd0558fa7951a4e466d09f34dd54bdffa5aab","hmac":"93c4907a457dc560c5bef27ce753aa7c4a45e961a70c260d2ccb5f1c13b4afbc","iv":"3fd47537bd9c19ad7c0e3a4ee86be124"}"
parameter 2: ""
parameter 3: true
now your statement (from the compiled code) is:
if (!t || "string" != typeof t)
throw new Error("Missing or invalid topic field");
so you throw because the topic is an empty string.
if i look at the call stack i see it went from _sendRequest(e, t)
e = "{"id":1595249132172380,"jsonrpc":"2.0","method":"wc_sessionUpdate","params":[{"approved":false,"chainId":null,"networkId":null,"accounts":null}]}"
t = undefined
it seems that it is falling back to this.peerId which is an empty string which then calls the above send
That's as much info as I can get which is useful.
any news on this @pedrouid
Is this still an issue?
I will upgrade to latest package and recheck for you tomorrow. 👍
no this is still a issue

Anything particular about the network or browser environment that I should know for reproducing it?
I am using a windows computer on the latest version of windows 10, google chrome again latest version. This happens on local as well as when deployed to aws for us. I also above explained every step I could to how it reproduces https://github.com/WalletConnect/walletconnect-monorepo/issues/315#issuecomment-661019926
so from you comment above it seems that you disconnect the session before calling send() is that correct?
at this point if your peer is disconnected then peerId would be an empty string which is invalid
unless there is another reason peerId would not be present but the only reason would be that the session is not connected so you should create a new connector and connect again
I'm getting this error too.
connector.createSession() does not update the _peerId value.
I'm getting the same error probably for the exact reason pedrouid indicated: I'm calling disconnect before sending anything. The reason I'm doing so it because I want to discard the old (cached) connection and scan a new QR code.
Maybe there is a more elegant way ensure that "startSession" actually starts a brand new connection and does not just reuse an old cashed connection?
PS: here is the workaround for my use case. If you want to make sure that walletconnect starts in a clean state, just delete its local storage before initializing it: window.localStorage.removeItem('walletconnect');
any update on this issue?
There should be some way to completely disconnect the session, currently it remembers last session, for one time even after calling disconnect so need to remove it from localstorage as mentioned in above workaround after disconnect.
Issue is existing since 2020 any update ?
Hi guys! Any update here? Also facing this issue on my side. Handling the error manually for now.
Also getting this myself
Same problem :/ But my app work anyway
@luziusmeisser 's window.localStorage.removeItem('walletconnect'); solution works except I sometimes get 2 QR codes when provider.enable() is triggered after window.localStorage.removeItem('walletconnect'); . Anybody knows the solution to this ?.
Same problem here :/ also subscribing
Same problem here when connecting to metamask via walletconnect on mobile
+1 Bumping this!
This issue was opened almost 2 years ago. C'mon dev team
Possible Unhandled Promise Rejection (id: 2):
Error: Missing or invalid topic field
Error: Missing or invalid topic field
at send (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:245697:26)
at _sendResponse$ (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:237871:37)
at call (native)
at tryCatch (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:28362:23)
at invoke (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:28532:32)
at anonymous (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:28404:30)
at call (native)
at tryCatch (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:28362:23)
at invoke (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:28434:30)
at anonymous (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:28444:21)
at tryCallOne (/Users/distiller/hermes/build_iphoneos/lib/InternalBytecode/InternalBytecode.js:53:16)
at anonymous (/Users/distiller/hermes/build_iphoneos/lib/InternalBytecode/InternalBytecode.js:139:27)
at apply (native)
at anonymous (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:33854:26)
at _callTimer (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:33750:17)
at _callReactNativeMicrotasksPass (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:33789:17)
at callReactNativeMicrotasks (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:33998:44)
at __callReactNativeMicrotasks (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:27201:46)
at anonymous (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:26980:45)
at __guard (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:27184:15)
at flushedQueue (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:26979:21)
at callFunctionReturnFlushedQueue (http://172.20.10.6:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.wallet:26961:33)
Facing this error when trying to approveSession. This is happening 1/5 times on an average.
is this still an issue?
I am still getting this issue
Putting the connection in a singleton and then nullifying the singleton allowed me to uncache the state without having to use the window.remove workaround.
class ConnectionWrapper {
private static _instance: ConnectionWrapper;
private _connector:any;
private constructor() {
this._connector = new client({bridge: "https://bridge.walletconnect.org", qrcodeModal: QRCodeModal});
}
public static getConnection():any {
if (!this._instance) {
this._instance = new ConnectionWrapper();
}
return this._instance;
}
public disconnect() {
this._connector.killSession();
this._connector = null;
ConnectionWrapper._instance = null;
}
get connector() {
return this._connector;
}
}
wrapper = ConnectionWrapper.getConnection();
wrapper.connector.createSession() // Shows new QR Code
wrapper.disconnect() // Throws topic error but removes cached data
same, I am still getting this issue
quick solution: Clean application browser cache and try again, that works for me but that can happen again
I encountered this issue, and was able to get past it. It seems like this happens when the params are not available. I checked my code, and there were some bugs which were not setting the required params correctly. Once I ensured everything was correct in code, this error was gone.
I solved this error by:
- Instead of using
wcProvider.disconnect(), i usedwcProvider.wc.killSession(). - Instead of reading connection status from
wcProvider.connected, I usedwcProvider.wc.session.connected.