cosmology-tech / cosmos-kit

Universal wallet connector for the Cosmos ⚛️
https://cosmology.zone/products/cosmos-kit
BSD 3-Clause Clear License
183 stars 134 forks source link

`getCosmWasmClient` throws error on custom chain #501

Open GiovaniGuizzoYUB opened 2 months ago

GiovaniGuizzoYUB commented 2 months ago

Hello. I am facing an issue with the method getCosmWasmClient from the useChain hook. For starters, I am using my own chain with a custom config. Here's the ChainProvider code (obfuscated):

    <ChainProvider
          chains={[MY_CHAIN]}
          assetLists={[MY_ASSETS]}
          wallets={wallets}
          sessionOptions={{ duration: 10800000 }}
          signerOptions={{
            signingStargate: () => {
              return {
                aminoTypes: myAminoTypes,
                registry: registry,
                gasPrice: GasPrice.fromString(`${DEFAULT_GAS_PRICE}${MY_DENOM}`),
              };
            },
            signingCosmwasm: () => {
              return {
                gasPrice: GasPrice.fromString(`${DEFAULT_GAS_PRICE}${MY_DENOM}`),
              };
            },
            preferredSignType: () => "amino",
          }}
          endpointOptions={{
            endpoints: {
              [MY_CHAIN.chain_name]: {
                rpc: [MY_CHAIN.apis!.rpc![0].address],
                rest: [MY_CHAIN.apis!.rest![0].address],
              },
            },
          }}
        >
        {children}
    </ChainProvider>

Calling const { getCosmWasmClient } = useChain(MY_CHAIN.chain_name); from the component and then trying to use getCosmWasmClient does not work. I get the following error:

Uncaught (in promise) Something wrong! Probably no valid RPC endpoint for chain my-chain

The interesting part is that getStargateClient works perfectly fine. It connects to my endpoints and I can even sign transactions normally. The problem is only with the getCosmWasmClient. It also throws a lot (hundreds) of errors like this:

Access to XMLHttpRequest at 'https://rpc.cosmos.directory/my-chain' from origin 'http://localhost:5173' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

It appears it is not using the endpoints I configured for cosmwasm, only for the regular stargate.

I am using v2.18.0. Any help is much appreciated.