Why SDK CDN dont work?

Hello, when I tried to use CDN:

MetaMaskSDK is not a constructor

But using with node modules works fine. Whats the problem?

Hello @user2149 !
Welcome to MetaMask community!

What version of @metamask/sdk are you using? 3.0.0 or 0.2.4 ?
Show the library import code.

3 Likes

Thanks for you reply.

Im using CDN from MetaMask docs:

https://docs.metamask.io/wallet/how-to/use-sdk/javascript/pure-js/

<script src="https://c0f4f41c-2f55-4863-921b-sdk-docs.github.io/cdn/metamask-sdk.js"></script>

1 Like

@user2149

Try pass an object with options as an argument in MetaMaskSDK like this:

<script>

    console.log(MetaMaskSDK);

    const opt = {
        forceInjectProvider: typeof window.ethereum === 'undefined',
    }

    const MMSDK = new MetaMaskSDK.MetaMaskSDK(opt);

    ethereum.request({method: 'eth_requestAccounts'})

</script>
3 Likes

thats work with

forceInjectProvider: true;

becauase forceInjectProvider receives a type bool, thanks for you solution!! Greetings.

2 Likes

@user2149 You may hardcode forceInjectProvider, but checking against window.ethereum is more flexible. :wink:

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.