Fortmatic
WebsiteDashboardSupport
v2.x
v2.x
  • 🚀Get Started
  • 📦Install with NPM
  • 🧩Examples
  • 💬FAQ
  • 📈Migrating from v1.x
  • Web3 Integration
    • Web3 Provider
    • Network Configuration
    • Binance Smart Chain
    • 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
  • More
    • Fiat On-ramp
    • Domain Verification
Powered by GitBook
On this page
  • Logging In
  • Sending a Transaction
  • Signing a Data

Was this helpful?

  1. Web3 Integration

SDK Error Handling

For logging in, signing data, or sending transactions, users can deny by simply closing the modal. On these events, Fortmatic SDK will throw an error to indicate that user has denied one of those actions.

Logging In

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

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

try {
  const accounts = await web3.eth.getAccounts();

  // other functions for logging in:
  // const accounts = await web3.currentProvider.enable();
  // const accounts = await fm.user.login();
}
catch (err) { // if user closes the modal without logging in
  console.log(err); // { message: 'Fortmatic: User denied account access.', code: '4001' }
}

Sending a Transaction

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

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

try {
  web3.eth.sendTransaction(...);
}
catch (err) { // if user closes the modal without starting the transaction
  console.log(err); // { message: 'Fortmatic: User denied transaction.', code: '-32603' }
}

Signing a Data

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

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

try {
  await web3.currentProvider.sendAsync(
  {
    id: 1,
    method: 'eth_signTypedData', // other function for signing: personal_sign
    params: [...]
  });
}
catch (err) { // if user closes the modal without signing
  console.log(err); // { message: 'Fortmatic: User denied transaction.', code: '-32603' }
}
PreviousUser SigningNextBatch Request

Last updated 5 years ago

Was this helpful?