🧑💻 Initialize
Initialize
When creating a Face object, you need an API Key and blockchain network parameters that you intend to use.
import { Face, Network } from '@haechi-labs/face-sdk';
const face = new Face({
network: Network.GOELRI,
apiKey: 'YOUR_DAPP_API_KEY'
});
Face
objects cannot be duplicated. For an object that was created, we recommend you manage and use it as a global variable or global state.
For integrating in React environment
For managing
Face
object as a global variable/state, you might use the Singleton pattern. If you don't need to change the blockchain network, the Singleton pattern is enough. But, if you're developing an web application in React and need to change blockchain network, you can manageFace
object as a global variable/state using a state management library like Recoil or Redux.You can find an example code using Recoil in here.
- Recoil makes you to be able to manage a global state via
Atom
.- Define and instantiate an atom for managing
Face
object as global state. (Example)
- When using the Recoil, it might be occurred an immutable error for changing of the value in Face object. So, you should set
dangerouslyAllowMutability
totrue
value when you create an Atom.- Initialize
Face
object and set it to recoil state. (Example)- When you want to use
Face
object in other place, get it using recoil value. (Example)
If you want to use chainId
, not Network
parameter, you can use it.
import { Face, Network } from '@haechi-labs/face-sdk';
const face = new Face({
network: 5, // Ethereum Goerli testnet's chain id is 5
apiKey: 'YOUR_DAPP_API_KEY'
});
Network Parameter
Face Wallet supports the following blockchain networks.
Blockchain | Mainnet Parameter | Testnet Parameter |
---|---|---|
Ethereum | Network.ETHEREUM | Network.SEPOLIA |
Polygon | Network.POLYGON | Network.MUMBAI |
BNB Smart Chain | Network.BNB_SMART_CHAIN | Network.BNB_SMART_CHAIN_TESTNET |
Klaytn | Network.KLAYTN | Network.BAOBAB |
BORA | Network.BORA | Network.BORA_TESTNET |
Solana | Network.SOLANA | Network.SOLANA_TESTNET |
NEAR | Network.NEAR | Network.NEAR_TESTNET |
Aptos | Network.APTOS | Network.APTOS_TESTNET |
MEVerse | Network.MEVERSE | Network.MEVERSE_TESTNET |
Oasys | Network.OASYS | Network.OASYS_TESTNET |
HOME Verse | Network.HOME_VERSE | Network.HOME_VERSE_TESTNET |
Yooldo Verse | Network.YOOLDO_VERSE | Network.SAND_VERSE |
MCH Verse | Network.MCH_VERSE | Network.MCH_VERSE_TESTNET |
DeFi Verse | Network.DEFI_VERSE | Network.DEFI_VERSE_TESTNET |
Hedera | Network.HEDERA | Network.HEDERA_TESTNET |
Kroma | Network.KROMA | Network.KROMA_TESTNET |
Linea | Network.LINEA | Network.LINEA_GOERLI |
API Key
You need an API Key to use Face Wallet SDK. You can have an API Key issued in Face Wallet Dashboard.
Advanced config
Notification Options
By default, Face Wallet display a toast message when the user completes their task (e.g., login, send a transaction, reeset PIN code, etc.).
Also, you can hide the toast message. So, you can display your custom notification instead of the default Face Wallet's toast message.
import { Face, Network } from '@haechi-labs/face-sdk';
const face = new Face({
network: Network.GOELRI,
apiKey: 'YOUR_DAPP_API_KEY',
notificationOptions: {
type: 'none' // 'toast', 'none'
}
});
If you initialized the Face
object with the type set to none
in notificationOptions
, when users finish their actions, the Face SDK will send the face-toast
event.
// face-toast Event
interface FaceToast {
message: {
title: string;
description: string;
},
type: 'default' | 'success' | 'error'
}
You can receive the face-toast
event on your dapp by registering an event listener for the face-toast
type.
const listener = (e: CustomEvent) => {
alert(`JSON.stringify(e?.detail)`);
};
window.addEventListener('face-toast', listener);
Updated 9 months ago