Fortmatic
WebsiteDashboardSupport
v1.x
v1.x
  • 🚀Get Started
  • 📦Install with NPM
  • 🧩Examples
  • 💬FAQ
  • Web3 Integration
    • Web3 Provider
    • Network Configuration
    • Get User Account
    • Send Ether Transaction
    • Smart Contract Functions
    • User Signing
    • SDK Error Handling
    • Batch Request
  • Smart Contract
    • ERC20 Transfer
    • ERC20 Approve
    • ERC20 TransferFrom
    • Generic Contract Call
  • Fortmatic Native
    • Log In
    • Log Out
    • Is User Logged In
    • Compose Transaction
    • Deposit Address
    • Configuration
  • Security
    • Domain Verification
Powered by GitBook
On this page
  • Replace Web3 Provider
  • MetaMask or dApp Browsers
  • Detecting the Fortmatic Provider

Was this helpful?

  1. Web3 Integration

Web3 Provider

If your dApp is written using web3 and already works with MetaMask, it's super easy to integrate with Fortmatic. All you have to do is to swap your existing web3 provider with the Fortmatic provider and continue developing in the same version of web3 you use.

Replace Web3 Provider

import Fortmatic from 'fortmatic';
// Works for web3 1.0 and pre-1.0 versions
import Web3 from 'web3';

const fm = new Fortmatic('YOUR_API_KEY');
window.web3 = new Web3(fm.getProvider());

MetaMask or dApp Browsers

You can also let existing users who have MetaMask installed to continue using MetaMask without disruption and direct new users without MetaMask to Fortmatic. This method also works with legacy dApp browsers.

import Fortmatic from 'fortmatic';
import Web3 from 'web3';

const fm = new Fortmatic('YOUR_API_KEY');

// Post EIP-1102 update which MetaMask no longer injects web3
if (window.ethereum) {
  // Use MetaMask provider
  window.web3 = new Web3(window.ethereum);
} else {
  // Use Fortmatic provider
  window.web3 = new Web3(fm.getProvider());
}

// Legacy dApp browsers which web3 is still being injected
if (typeof web3 !== 'undefined') {
  // Use injected provider
  window.web3 = new Web3(web3.currentProvider);
} else {
  // Use Fortmatic provider
  window.web3 = new Web3(fm.getProvider());
}

Detecting the Fortmatic Provider

As a convenience, you can detect the Fortmatic web3 provider by checking for an isFortmatic property on the provider object. The following lines of code should evaluate to true when using the Fortmatic provider:

import Fortmatic from 'fortmatic';
import Web3 from 'web3';

const fm = new Fortmatic('YOUR_API_KEY');

fm.getProvider().isFortmatic // => true

window.web3 = new Web3(fm.getProvider());
window.web3.currentProvider.isFortmatic // => true
PreviousFAQNextNetwork Configuration

Last updated 5 years ago

Was this helpful?