cosmology-tech / cosmos-kit

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

[@cosmos-kit/cosmos-extension-metamask]Coin type 60 is forbidden #405

Open eric-notifi opened 4 months ago

eric-notifi commented 4 months ago

Hey team, We are running into a situation when building a dapp with cosmos-kit react wallet on Injective chain


import { wallets as metaMaskWallets } from '@cosmos-kit/cosmos-extension-metamask';
import { wallets as keplrWallets } from '@cosmos-kit/keplr';

export const CosmosWalletProvider: FC<PropsWithChildren> = ({ children }) => {

  return (
    <ChainProvider
      chains={[injChain]} // https://github.com/cosmos/chain-registry/blob/master/injective/chain.json
      assetLists={[assetList]}
      wallets={[...keplrWallets, ...metaMaskWallets]}
    >
      {children}
    </ChainProvider>
  );
};

Keplr is working like a charm, but Metamask is not working as expected. There are two scenarios:

  1. The wallet is successfully connected, but the "inj" address seems not correct. (different from the one showing in injective hub. See the video below):

https://github.com/cosmology-tech/cosmos-kit/assets/127958634/6bfdef5c-1d6f-4354-b5d9-f1b31504df73

  1. The error Coin type 60 is forbidden is thrown when I try to use client.signArbitrary.
Screenshot 2024-02-21 at 19 24 02

Code:

 const { client, status } = useWalletClient();
//...

        <div
          onClick={() => {
            if (client?.signArbitrary && client.getAccount) {
              client.getAccount('injective-1').then((account) => {
                // Along with the following 'arr', I also tried inj addr and eth hex addr. But still no luck
                const arr = Buffer.from(
                  new Uint8Array(Object.values(account.pubkey)),
                ).toString('base64');
                console.log({ addr: arr });
                client?.signArbitrary?.('injective-1', arr, 'test');
              });
            }
          }}
        >
          Sign with metamask
       </div>
//...

Not sure if it is caused by INJ chain's being not supported (or even the .signArbitrary is not support using Metamask?). Please point me out if I miss anything.

schnetzlerjoe commented 1 month ago

@eric-notifi Hello! Thanks for this. The issue you are seeing is because Coin Type 60 is the coin type for all native Metamask addresses and they block Coin Type 60 in the Metamask Snap SDK. Thus any coin type 60 chains are supported natively by Metamask, not with the Cosmos Extension for Metamask.

Hope that clears it up!