secret.js icon indicating copy to clipboard operation
secret.js copied to clipboard

Get "Unmatched chain id with the offline signer" with last updates

Open zhmoly opened this issue 2 years ago • 4 comments

I used secretjs alpha version before. And used keplr wallet for query & broadcast transactions. It was works fine before I updated secretjs version. But when I update with v1.5, get this error: "Unmatched chain id with the offline signer". Of course, set chainid as "pulsar-2" for both client side and wallet setting.

this.scrtSecretJs = new SecretNetworkClient({ url: env.grpcurl, chainId: env.CHAIN_ID, wallet: keplrOfflineSigner, walletAddress: this.scrtUsrPubkey, encryptionUtils: this.scrtKeplr.getEnigmaUtils(env.CHAIN_ID), });

After my own research, I find this issue related with parameter names. For old version, there is _ for parameters. (ex: chain_id => chainId, code_id => codeId). But names updated and some wallet sdk (not sure that) is just working with chain_id.

This one is what I find that error part in CosmJSOfflineSigner. (from chrome console, not from github source). e.CosmJSOfflineSigner = class extends i { constructor(t, e) { super(t, e), this.chainId = t, this.keplr = e } signDirect(t, e) { return n(this, void 0, void 0, (function*() { if (this.chainId !== e.chainId) throw new Error("Unmatched chain id with the offline signer"); if ((yield this.keplr.getKey(e.chainId)).bech32Address !== t) throw new Error("Unknown signer address"); return yield this.keplr.signDirect(this.chainId, t, e) } )) } }

And this is chainId compare part. image

So chainId is same, but name is different. Is there any way to resolve this issue? Thanks

zhmoly avatar Dec 23 '22 06:12 zhmoly

Hey @jwtradera! The interfaces for v1.5 have changed a bit as a result of the switch to grpc-gateway. I suspect your issue may be incorrect initialization of SecretNetworkClient. The correct way to initialize the SecretNetworkClient is with a REST url, not the GRPC. You can find an example of how to initialize SecretJS & Keplr here:

https://github.com/scrtlabs/rps-ui/blob/main/store/index.js#L79

Let me know if this helps!

Cashmaney avatar Dec 23 '22 09:12 Cashmaney

Hi Thanks for reply. Just if possible, can you share NUXT_ENV_REST_URL? I'm using 'pulsar-2' for test, so if possible can you share that url? Also I both tried grpc and lcd url for that. And if I using grpc not lcd, then get http1.2 issue. If you faced same issue, can you forward that solution too? Many thanks

zhmoly avatar Dec 23 '22 11:12 zhmoly

That endpoint is a mainnet one, and from your chain-id it seems like you're trying to connect to the pulsar-2 testnet. You can use any of the endpoints publicly available from here: https://docs.scrt.network/secret-network-documentation/development/connecting-to-the-network

Cashmaney avatar Dec 23 '22 17:12 Cashmaney

This should be fixed in v1.6.10, can you confirm @jwtradera?

assafmo avatar Jan 25 '23 08:01 assafmo