Get User Account
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
// 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();// 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...'
});