Abstract Wallet
The base class for any wallet in the Wallet SDK, including backend wallets. It contains the functionality common to all wallets.
This wallet is not meant to be used directly, but instead be extended to build your own wallet.
Usage
export class MyCustomWallet extends AbstractWallet {
async getSigner(): Promise<Signer> {
// your implementation
}
}
Public Methods
getAddress
Get the address of the currently connected wallet.
const address = await wallet.getAddress();
Configuration
getChainId
Get the chain ID of the network the wallet is currently connected to.
const chainId = await wallet.getChainId();
Configuration
transfer
Transfer native or ERC20 tokens from this wallet to another wallet
// for native tokens
const txResult = await wallet.transfer(recipientAddress, amount);
// for ERC20 tokens
const txResult = await wallet.transfer(recipientAddress, amount, tokenAddress);
Configuration
getBalance
Get the the native token balance or ERC20 token balance of the wallet.
// for native token balance
const balance = await wallet.getBalance();
// for ERC20 token balance
const balance = await wallet.getBalance(tokenAddress);
Configuration
getSigner
Get the signer
for the currently connected wallet.
const signer = await wallet.getSigner();
Configuration
signMessage
Sign a message with the currently connected wallet. This function must be implemented by the parent class.
const signature = await wallet.signMessage("Hello world!");
Configuration
verifySignature
Verify a signature is valid.
const isValid = await wallet.verifySignature(
"Message",
"Signature",
"wallet_address",
);
Configuration
Events
Abstract Wallet implements EventEmitter, and emits useful events to track the connection lifecycle.
wallet.on("connect", {
console.log("connected");
});