1

There is some hype about DeFi and it goes basically to Ethereum
(I have not seen yet other non-Ethereum blockchain that prmote DeFi term usage). Then there is MetaMask that is essential a wallet distributed as Chrome browser plugin.

But some blockchain site specifically require MetaMask and establish some communication between.

I know Ethereum, but it is blockchain and basically backend technology.
I think is has nothing to do with browsers and websites.

What exactly (technically speaking) is Ethereum blockchain enabled website?
Or other way round, how exactly MetaMask is to interact with website visited?

Paul Verest
  • 60,022
  • 51
  • 208
  • 332

2 Answers2

2

How websites interact with the MetaMask extension

Metamask extension injects the ethereum property into the JS window object. This property links to the JS API of the Metamask extension, allowing the website some level of control - such as "open a window requesting the user to submit this transaction" (but not "get the private key" for example).

This example JS code opens the Metamask window and asks the user for permission to share their (public) addresses with the website, when the myBtn is clicked. The shared addresses are then saved into the accounts variable.

$('#myBtn').click(async (e) => {
    let accounts = await window.ethereum.request({
        'method': 'eth_requestAccounts'
    });
}

You can find more info at https://docs.metamask.io/guide/getting-started.html#getting-started

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • 1
    Thanks for pointing, so it is "Ethereum Provider API" https://docs.metamask.io/guide/ethereum-provider.html that should be implementation of "EIP-1193: Ethereum Provider JavaScript API" https://eips.ethereum.org/EIPS/eip-1193#api – Paul Verest Apr 08 '21 at 01:45
1

Basically in a decentralised application (DApp) the HTML frontend directly interacts with the blockchain without going through a web server. This is done with a wallet, existing independently from the DApp, confirms all the transactions. Any sent transaction goes directly from the frontend to the Ethereum blockchain through a JSON-RPC API node (see link for the request round trip description).

The main differences to the centralised web applications using server-side backend

  • The backend developer cannot break the terms of the (smart) contract, e.g. steal users money into his own pocket. This is called non-custodial model and it mitigates counterparty risk.

  • Backend cannot pull money or make user to do something they cannot accept, because wallet confirms all the transaction. Users, or their sophisticated representatives, can double check all smart contracts the wallet is going to interact on a blockchain.

  • Blockchain never goes down, unlike centralised services, because it is highly distributed (10,000 nodes)

  • User pays for all the transaction themselves using ETH as the currency for the transaction fees.

Note that the model is not exclusive to Ethereum, but also used by many other blockchains. Live DeFi applications can be found e.g. on EOS, Solana and NEAR blockchains and many Ethereum Virtual Machine compatible chains like Polygon, Avalanche and Binance Smart Chain.

Note that currently most users still need to trust the HTML code downloaded from some centralised web server. We have seen e.g. DNS takeover attacks in the past. However, this still greatly reduces the risk, as any "sign-in" to a web application does not automatically put the user in risk, as wallets still need to confirm any transaction.

Also note that blockchain makes little sense for applications that do not involve financial assets or other assets with value, like NFTs, because the main use case of a blockchain is to solve financial sovereignty and eliminate counterparty risk. This tradeoff comes with high transaction costs and the need of some sort of cryptocurrency.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435