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

1
import Fortmatic from 'fortmatic';
2
import Web3 from 'web3';
3
​
4
const fm = new Fortmatic('YOUR_API_KEY');
5
window.web3 = new Web3(fm.getProvider());
6
​
7
try {
8
const accounts = await web3.eth.getAccounts();
9
​
10
// other functions for logging in:
11
// const accounts = await web3.currentProvider.enable();
12
// const accounts = await fm.user.login();
13
}
14
catch (err) { // if user closes the modal without logging in
15
console.log(err); // { message: 'Fortmatic: User denied account access.', code: '4001' }
16
}
Copied!

Sending a Transaction

1
import Fortmatic from 'fortmatic';
2
import Web3 from 'web3';
3
​
4
const fm = new Fortmatic('YOUR_API_KEY');
5
window.web3 = new Web3(fm.getProvider());
6
​
7
try {
8
web3.eth.sendTransaction(...);
9
}
10
catch (err) { // if user closes the modal without starting the transaction
11
console.log(err); // { message: 'Fortmatic: User denied transaction.', code: '-32603' }
12
}
Copied!

Signing a Data

1
import Fortmatic from 'fortmatic';
2
import Web3 from 'web3';
3
​
4
const fm = new Fortmatic('YOUR_API_KEY');
5
window.web3 = new Web3(fm.getProvider());
6
​
7
try {
8
await web3.currentProvider.sendAsync(
9
{
10
id: 1,
11
method: 'eth_signTypedData', // other function for signing: personal_sign
12
params: [...]
13
});
14
}
15
catch (err) { // if user closes the modal without signing
16
console.log(err); // { message: 'Fortmatic: User denied transaction.', code: '-32603' }
17
}
Copied!
Last modified 2yr ago