Skip to main content

Use MetaMask SDK with pure JavaScript

You can import MetaMask SDK into your pure JavaScript dapp to enable your users to easily connect with a MetaMask wallet client. The SDK for pure JavaScript works the same way and has the same prerequisites as for standard JavaScript and other web frameworks.

To import, instantiate, and use the SDK, you can insert a script in the head section of your website:

<head>
...

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

<script>

const MMSDK = new MetaMaskSDK()

const ethereum = MMSDK.getProvider() // You can also access via window.ethereum

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

</script>

...
</head>

You can configure the SDK using any options and call any provider API methods. Always call eth_requestAccounts using ethereum.request() first, since it prompts the installation or connection popup to appear.