Use MetaMask SDK with Node.js
Import MetaMask SDK into your Node.js dapp to enable your users to easily connect to the MetaMask browser extension and MetaMask Mobile. The SDK for Node.js has the same prerequisites as for standard JavaScript.
Example
See the example Node.js dapp in the JavaScript SDK GitHub repository for advanced use cases.
Steps
1. Install the SDK
In your project directory, install the SDK using Yarn or npm:
yarn add @metamask/sdk
or
npm i @metamask/sdk
2. Import the SDK
In your project script, add the following to import the SDK:
import { MetaMaskSDK } from '@metamask/sdk';
3. Instantiate the SDK
Instantiate the SDK using any options:
const MMSDK = new MetaMaskSDK(options);
const ethereum = MMSDK.getProvider(); // You can also access via window.ethereum
Important SDK options
- Use
dappMetadata
to display information about your dapp in the MetaMask connection modal. - Use
modals
to customize the logic and UI of the displayed modals. - Use
infuraAPIKey
to make read-only RPC requests from your dapp.
4. Use the SDK
Use the SDK by calling any provider API methods.
Always call eth_requestAccounts
using
ethereum.request()
first, since it
prompts the installation or connection popup to appear.
ethereum.request({ method: 'eth_requestAccounts', params: [] });