Skip to content

How to Connect to a DApp with MetaMask

    Decentralized Applications (DApps) rely on public blockchains like Ethereum. These blockchains function as distributed databases accessible via the internet. MetaMask facilitates connections to such databases, similar to how a web browser interacts with web pages. To establish this connection, MetaMask must be directed to what blockchain engineers refer to as RPC endpoints.

    Data Exchange Between Applications

    In the early stages of the internet (Web 1.0 and 2.0), HTTP served as the standard protocol for data exchange. When applications communicate with each other, they utilize HTTP. However, the data transmitted or received must adhere to a specific format, typically XML or JSON. XML, or eXtensible Markup Language, employs a tag structure to describe the content of digital documents. For example:

    <employees>
      <employee>
        <firstName>John</firstName> <lastName>Doe</lastName>
      </employee>
      <employee>
        <firstName>Anna</firstName> <lastName>Smith</lastName>
      </employee>
      <employee>
        <firstName>Peter</firstName> <lastName>Jones</lastName>
      </employee>
    </employees>

    On the other hand, JSON, standing for JavaScript Object Notation, is a text-based data exchange format derived from JavaScript. JSON’s simplicity, compatibility with JavaScript, compactness, ability to produce smaller files, and facilitate faster data transfer make it the preferred choice for data exchange in web applications. Here is an example of JSON notation:

    {"employees":[
    { "firstName":"John", "lastName":"Doe" },
    { "firstName":"Anna", "lastName":"Smith" },
    { "firstName":"Peter", "lastName":"Jones" }
    ]}

    Connecting Applications

    MetaMask interacts with RPC endpoints, which enable Remote Procedure Calls (RPC) between applications. RPC allows a program on one machine to remotely execute a specific function or procedure on another machine without needing to know its exact location. This communication occurs through Application Programming Interfaces (APIs), which facilitate the exchange of information between websites or apps and users.

    DApps like MetaMask utilize the JSON-RPC protocol for communication. JSON-RPC, based on JSON, enables software applications to invoke functionalities from other applications. RPC endpoints serve as access points for sending requests to the blockchain.

    Connecting MetaMask to a DApp

    When accessing a DApp webpage with MetaMask, establishing a connection is necessary. This process allows the DApp to access your wallet address and view associated funds on the blockchain. Typically, clicking a “connect with MetaMask” button prompts the connection process. However some legacy sites may not request access properly. If the dapp to which you’re trying to connect doesn’t automatically prompt you to connect your MetaMask, you’ll need to add it manually. Here’s how to do it:

    1. Navigate to the site you want to manually connect to, and then click on the MetaMask Extension icon in the browser toolbar in the top-right. This will open MetaMask.
    2. In MetaMask, click on the three dots menu in the upper right corner, and then on Connected sites.
    3. Click the Manually connect to current site button at the bottom of the list (please note that this button will not appear if one of your other accounts is linked to the dapp or if you have another wallet installed in your browser that has an account linked to the dapp)
    4. Next, select the account(s) you want to connect, then follow the prompts to confirm the process.

    Disconnecting MetaMask from a DApp

    To sever the connection between MetaMask and a DApp:

    1. Open MetaMask and navigate to the Account view.
    2. Click the three dots button in the top right corner and select “Connected Sites.”
    3. Click “Disconnect” next to the desired site(s) to remove the connection (if you have multiple accounts connected to the same site, the option to remove connections from all of your accounts will appear when you click disconnect:).

    By following these steps, users can efficiently manage their connections between MetaMask and DApps, ensuring privacy and security.