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
  • Trigger User Login Modal
  • Web3 Methods

Was this helpful?

  1. Web3 Integration

Get User Account

PreviousNetwork ConfigurationNextSend Ether Transaction

Last updated 5 years ago

Was this helpful?

In order for web3 to work and grab the end-users' Ethereum wallet addresses, the users have to login first (similar to unlocking account in MetaMask). You can simply trigger the login for users with the web3 function call below.

Trigger User Login Modal

In accordance with the , developers who are using web3 can trigger user login modal with the enable() method in the provider.

// Initialize provider
import Fortmatic from 'fortmatic';
import Web3 from 'web3';

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

// Request user login if needed, returns current user account address
web3.currentProvider.enable();

Web3 Methods

User login modal can also be triggered through web3 accounts and coinbase functions.

// Initialize provider
import Fortmatic from 'fortmatic';
import Web3 from 'web3';

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

// Sync functions that returns users' addresses if they are already logged in with enable().
// Not recommended as sync functions will be deprecated in web3 1.0
console.log(web3.eth.accounts); // ['0x...']
console.log(web3.eth.coinbase); // '0x...'

// Async functions that triggers login modal, if user not already logged in
web3.eth.getAccounts((error, accounts) => {
  if (error) throw error;
  console.log(accounts); // ['0x...']
});
web3.eth.getCoinbase((error, coinbase) => {
  if (error) throw error;
  console.log(coinbase); // '0x...'
});
// Initialize provider
import Fortmatic from 'fortmatic';
import Web3 from 'web3';

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

// Async functions that triggers login modal, if user not already logged in
web3.eth.getAccounts().then((accounts) => {
  console.log(accounts); // ['0x...']
});
web3.eth.getCoinbase().then((coinbase) => {
  console.log(coinbase) // '0x...'
});

A modal will open to ask users to sign up for an account or login with their mobile phone number.

🎁When you create a Fortmatic account on testnet, we'll automatically send 1 ETH (on Rinkeby testnet) to your account to play with.

EIP-1102 update