sailor95 / metamask-sdk

The simplest yet most secure way to connect your blockchain-based applications to millions of MetaMask Wallet users.

Home Page:https://metamask.io/sdk/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MetaMask SDK

The MetaMask SDK enables developers to easily connect their dapps with a MetaMask wallet (Extension or Mobile) no matter the dapp environment or platform.

The MetaMask SDK is a library that can be installed by developers on their projects and will automatically guide their users to easily connect with a MetaMask wallet client. For instance, for dapps running on a desktop browser, the SDK will check if Extension is installed and if not it will prompt the user to install it or to connect via QR code with their MetaMask Mobile wallet. Another example, for native mobile applications, the SDK will automatically deeplink into MetaMask Mobile wallet to make the connection.

The MetaMask SDK instance returns a provider, this provider is the ethereum object that developers are already used to which is here. This provider will now be available for:

Features

  • Session persistence
  • Multi Provider (Let user choose between browser extension and mobile wallet)
  • Wagmi Hook Integration (alpha)
  • i18n throuhg Modal customization
  • smart contract library ( upcoming )

Getting Started

The following code examplifies importing the SDK into a javascript-based app. For other languages, check the sections bellow.

Install the SDK:

yarn add @metamask/sdk
or
npm i @metamask/sdk

Web (d)apps

Follow example on:

React Native

We recommend using RN v0.71.4 or higher otherwise you may encounter significant performance issues on Android.

Follow example on:

NodeJS

import { MetaMaskSDK } from '@metamask/sdk';
const MMSDK = new MetaMaskSDK({
  dappMetadata: {
    name: 'NodeJS example',
  }
});
MMSDK.connect()
  .then((accounts) => {
    console.log('MetaMask SDK is connected', accounts);
    const ethereum = MMSDK.getProvider();
    const ethereum = sdk.getProvider();
    const balance = await ethereum.request({
      method: 'eth_getBalance',
      params: accounts,
    });

    console.debug(`account balance`, balance);
  })
  .catch((error) => {
    console.error(error);
  });

Electron

Follow example on:

SDK Options

You can find the full interface in sdk.ts file but here are the useful options:

  • checkInstallationImmediately: boolean (default: false) - If true, the SDK will check if MetaMask is installed on the user's browser and send a connection request. If not it will prompt the user to install it. If false, the SDK will wait for the connect method to be called to check if MetaMask is installed.

  • useDeeplink: boolean (default: false) - If true, the SDK will use deeplinks to connect with MetaMask Mobile. If false, the SDK will use universal links to connect with MetaMask Mobile.

  • shouldShimWeb3: boolean (default: false) - If true, the SDK will shim the window.web3 object with the provider returned by the SDK (useful for compatibility with older browser).

  • enableDebug: boolean (default: true) - Send anonymous analytics to MetaMask to help us improve the SDK.

  • modals: see nodejs example to customize or translate each of the displayed modals.

Contributing

Please see our contributing guidelines for more information.

About

The simplest yet most secure way to connect your blockchain-based applications to millions of MetaMask Wallet users.

https://metamask.io/sdk/

License:Other


Languages

Language:TypeScript 72.5%Language:JavaScript 17.4%Language:Java 2.4%Language:CSS 1.6%Language:HTML 1.5%Language:Shell 1.1%Language:Vue 0.8%Language:Ruby 0.8%Language:Objective-C 0.8%Language:Objective-C++ 0.4%Language:C 0.3%Language:SCSS 0.3%Language:Go 0.2%Language:Dockerfile 0.0%