SDK contains all the core functionality related to zbyte wallet, and can be supported on browser(client side code).
npm install @zbyteio/zbyte-wallet-sdk-core
The zbyte core wallet manages user account creation and interacts with the DPLAT token. Key features include:
- Viewing the current DPLAT balance and transferring it to another account.
- Support for Polygon and Avalanche C-Chain blockchains.
- Management of key pairs through third-party libraries referred to as External Key Providers (EKP).
- Current supported EKPs include Web3auth and Metamask.
Since the DPLAT token is not a Layer 1 (L1) token, zbyte wallet defines some mandatory interfaces:
IWalletProvider
interface IWalletProvider {
/**
* @description Connect to the wallet provider.
*/
connect(): Promise<any>;
/**
* @description Check if the wallet provider is connected.
*/
isConnected(): boolean;
/**
* @description Fetch the wallet provider which internally sets the provider.
* @param networkConfig Blockchain Network parameters.
*/
getKeyProvider(networkConfig: NetworkConfig): Promise<IKeyProvider>;
}
IKeyProvider
interface IWalletProvider {
/**
* @description Connect to the wallet provider.
*/
connect(): Promise<any>;
/**
* @description Check if the wallet provider is connected.
*/
isConnected(): boolean;
/**
* @description Fetch the wallet provider which internally sets the provider.
* @param networkConfig Blockchain Network parameters.
*/
getKeyProvider(networkConfig: NetworkConfig): Promise<IKeyProvider>;
}
-
isConnected()
- Checks whether the wallet is connected to an underlying key provider like Web3auth or Metamask.
-
connect()
- Connects to an underlying key provider
-
signTypedData(txnMessage: string, chainId: number)
- Signs an EIP-712 transaction.
- Inputs:
- txnMessage: Serialized EIP-712 message.
- chainId: Blockchain ID that requires the signature.
-
getAddress()
- Returns the blockchain address for the user.
-
getTokenBalance(address: string)
- Provides the zbyte token balance for the given user's address.
- Input:
- address: User's blockchain address.
Below is an example of how to use the wallet SDK:
const web3Auth = new Web3AuthProvider();
const metamask = new MetaMaskProvider();
const walletProvider: IWalletProvider = web3Auth || metamask;
const wallet = new WalletCore(walletProvider, getBlockchainNetwork(CHAIN_ID_MATIC_TESTNET));
// For using Web3auth, the default and preferred provider,
// an extra authentication function is required
wallet.injectAuthVerifier({
clientId: string;
domain: string;
typeOfLogin?: LOGIN_TYPE;
verifier: string;
accessToken: string;
tokenExpiry?: number;
typeOfToken?: string;
});
if (!wallet.isConnected()) {
console.log(await wallet.connect()
.then((result) => {
console.log("initialized");
return result;
})
.catch(e => console.error(e)));
}
const userAddress = await wallet.getAddress();
const dplatBalance = await wallet.getTokenBalance(userAddress);
For further details and advanced usage, please refer to the official documentation.