# Providers

As explained previously, the 0xcert ecosystem tends to be platform-agnostic, thus it is not created for merely one blockchain or one specific platform. It aims to provide a consistently optimal developing experience, regardless of the platform you employ. To achieve this, the 0xcert ecosystem consists of several modules, and each module needs a provider object to tell the module how to operate. Each provider operates on the same principles, but can also have its own distinctive characteristics.

Even within the same blockchain, you can use multiple providers depending on your needs. If you would like to communicate with the blockchain on the front-end, you could use MetamaskProvider, while for communication on the back-end you could use HttpProvider. For more information about other providers for Ethereum, such as Bitski, please click here.

In this guide, we will be using the MetaMask provider for the Ethereum blockchain. MetaMask is a popular plug-in that allows you to create and store the private keys for your Ethereum account inside your browser or mobile device. It works as a bridge between your browser and the Ethereum blockchain through its own infrastructure. MetaMask can also be paired with hardware wallets such as Ledger or Trezor.

Live example

Click here to check the live example for this section.

# Installation process

We recommend you employ the provider module as an NPM package in your application.

$ npm i --save @0xcert/ethereum-metamask-provider

On our official GitHub repository, we also host a compiled and minimized JavaScript file that can be directly implemented into your website. Please refer to the API section to learn more about other providers.

# Usage overview

To start developing the application, we have to first instantiate the MetamaskProvider provider class. This is usually only needed once within the application. When initializing we also set the gateway config. This is needed for the 0xcert API client to work properly.

import { MetamaskProvider, buildGatewayConfig, NetworkKind } from '@0xcert/ethereum-metamask-provider';

const provider = new MetamaskProvider({
  gatewayConfig: buildGatewayConfig(NetworkKind.RINKEBY)
});

MetaMask needs to be authorized and unlocked to be used on the website. This is specific to this provider. Therefore, before you start interacting with the Ethereum node, you should check whether the MetaMask account has been enabled. If not, you have to enable it, as shown in the example below.

if (!await provider.isEnabled()) {
  await provider.enable();
}