debeem-wallet
v1.0.70
Published
Ethereum Wallet by DeBeem, Team.
Downloads
306
Readme
debeem-wallet
A complete, compact, and simple Ethereum wallet library based on the ethers library.
Table of contents
Features
- Easy to use, whether you have experience in Ethereum wallet development or not, you can easily get started.
- Provides complete functions such as creation, import, and backup of Ethereum wallets.
- Provides balance query, total value statistics, and real-time trading pair quotes for Ethereum native token and derivative tokens.
- Provides transfer, real-time transaction gas fee estimating, transaction history query, transaction details query, and transaction receipt query functions for Ethereum native token and derivative tokens.
- Provides information query for Ethereum native token and derivative tokens.
- Provides network information query by chainId.
- Provide local structured data storage based on AES256 encryption algorithm, and the password can be modified at will.
Architecture
UML Graph
flowchart TD
id([debeem-id])
cipher([debeem-cipher])
ethers([ethers])
idb([idb])
ethers -. «extend» .-> root
id -. «extend» .-> root
cipher -. «extend» .-> root
idb -. «extend» .-> root
subgraph debeem-wallet
root([debeem-wallet])
config(Config)
walletServices(Wallet Services)
storageServices(Storage Services)
chainService(Chain Service)
tokenService(Token Service)
root --- config
root --- walletServices
root --- storageServices
root --- chainService
root --- tokenService
%% wallet service list
walletServiceList["WalletFactory
WalletAccount
WalletTransaction
WalletNFT"]
walletServices --- walletServiceList
%% storage service list
encryptedStorageServices(Encrypted Storage Services)
storageServicesList["SysUserStorageService
BasicStorageService
ChainStorageService
TokenStorageService
WalletStorageService"]
storageServices --- encryptedStorageServices
encryptedStorageServices --- storageServicesList
%% chain service list
tokenServiceList["TokenService"]
tokenService --- tokenServiceList
%% token service list
chainServiceList["ChainService"]
chainService --- chainServiceList
end
Dependency Packages
Installation
1, install nvm
use the following cURL or Wget command to install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
2, install node
install the latest LTS version of node, for example: v18.20.3 (Latest LTS: Hydrogen)
nvm install v18.20.3
nvm use v18.20.3
3, install our package
npm i debeem-wallet
to fix issue: Module not found: Error: Can't resolve 'fake-indexeddb/auto'
npm i -D fake-indexeddb
Configuration
About chain
There are many chains in the entire blockchain world, such as the Bitcoin chain, Ethereum chain, etc. Every wallet MUST work on a certain chain (or call it a network).
So, before using any functions or classes in this development package, you MUST first configure a chain/network for your wallet.
View all chains on:
https://chainlist.org/
Configurations
1, Chain Configuration
| Function | Invocations | Storage | Description | |---------------------------------------------------------------------------------------------------------------------------------------|-------------|----------|--------------------------------------------------------------------------------------------| | getDefaultChain | sync | memory | get default chainId from memory | | getCurrentChain | sync | memory | get current chainId from memory | | setCurrentChain | sync | memory | set/update current chainId to memory | | revertToDefaultChain | sync | memory | revert the current chain to the default value in memory | | getCurrentChainAsync | async | database | asynchronously get current chainId from the database | | putCurrentChainAsync | async | database | asynchronously set/update current chainId into the database | | revertToDefaultChainAsync | async | database | asynchronously revert the current chain to the default value and save it into the database |
2, Wallet Configuration
| Function | Invocations | Storage | Description | |-------------------------------------------------------------------------------------------------------------------------------|-------------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | getCurrentWalletAsync | async | database | asynchronously get current wallet from the database | | putCurrentWalletAsync | async | database | asynchronously put current wallet into the database | | initWalletAsync | async | database | asynchronously create or recover an account. For detailed usage instructions, please refer to the unit tests: config.test.ts, SysUserStorageService.test.ts, WalletStorageService.test.ts. |
Usage
Wallet Services
| Class | Description | |----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------| | WalletFactory | create a new wallet, or import a wallet from a mnemonic, keystore, private key or a wallet address | | WalletAccount | query balance, calculate total value, and request quotes in real-time for the Ethereum native token or any derivative tokens | | WalletTransaction | send and receive your Ethereum native token or any derivative tokens, estimate transaction gas fee, and query transaction history, details and receipt | | WalletNFT | query NFTs information |
Storage Services
| Class | Description | |------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------| | SysUserStorageService | manage encryption information table and modify PIN code | | BasicStorageService | simple storage based on key-value | | ChainStorageService | get the default supported chain list, get information of a chain, add, delete and update the information of a chain | | TokenStorageService | manage tokens of a wallet on a specified chain. get the token list, add, delete and update the token information | | WalletStorageService | based on secure encryption, obtain information of a wallet, add, delete and update a wallet |
Chain Service
| Class | Description | |------------------------------------------------|----------------------------------------------------------------------------| | ChainService | check whether a chain exists and obtain the chain information by chain id. |
Token Service
| Class | Description | |------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------| | TokenService | check whether a token exists and obtain the token information by contract address. |
Unit Tests
This project has complete unit tests with an average coverage of over 90%. Run the unit tests in the project root directory:
jest