p-sdk-wallet
Version:
A comprehensive wallet SDK for React Native (pwc), supporting multi-chain and multi-account features.
85 lines (84 loc) • 3.86 kB
TypeScript
import { TransactionRequest, TransactionResponse, TransactionReceipt } from 'ethers';
import { type ChainConfig } from '../config/chains';
/**
* Interface representing token metadata for ERC-20 tokens.
*/
export interface Token {
/** The contract address of the token */
address: string;
/** The human-readable name of the token */
name: string;
/** The token's symbol/ticker */
symbol: string;
/** The number of decimal places for the token */
decimals: number;
}
/**
* Service for interacting with EVM-compatible blockchains.
* Provides methods for balance checking, token operations, and transaction sending.
*/
export declare class ChainService {
private wallet;
/**
* Creates a new ChainService instance for the specified chain.
* @param privateKey - The private key to use for signing transactions (hex string without '0x' prefix)
* @param chainConfig - The chain configuration to use
*/
constructor(privateKey: string, chainConfig: ChainConfig);
/**
* Derives the public address from a private key.
* @param privateKey - The private key to derive the address from (hex string without '0x' prefix)
* @returns The derived Ethereum address
*/
static getAddress(privateKey: string): string;
/**
* Gets the native token balance (e.g., ETH, MATIC) for the wallet.
* @returns Promise resolving to the balance as a bigint in wei
* @throws Error if the provider is not set
*/
getNativeBalance(): Promise<bigint>;
/**
* Gets the balance of a specific ERC-20 token for the wallet.
* @param tokenAddress - The contract address of the ERC-20 token
* @returns Promise resolving to the token balance as a bigint
* @throws Error if the provider is not set or token contract is invalid
*/
getTokenBalance(tokenAddress: string): Promise<bigint>;
/**
* Gets metadata information about an ERC-20 token.
* @param tokenAddress - The contract address of the ERC-20 token
* @returns Promise resolving to token metadata including name, symbol, and decimals
* @throws Error if the provider is not set or token contract is invalid
*/
getTokenInfo(tokenAddress: string): Promise<Token>;
/**
* Estimates the gas cost for a transaction.
* @param transaction - The transaction request to estimate gas for
* @returns Promise resolving to the estimated gas cost as a bigint
* @throws Error if the provider is not set or estimation fails
*/
estimateGas(transaction: TransactionRequest): Promise<bigint>;
/**
* Sends a transaction to the blockchain.
* @param transaction - The transaction request to send
* @returns Promise resolving to the transaction response with hash and details
* @throws Error if the transaction fails or wallet is not properly configured
*/
sendTransaction(transaction: TransactionRequest): Promise<TransactionResponse>;
/**
* Sends ERC-20 tokens to another address.
* @param tokenAddress - The contract address of the ERC-20 token to send
* @param to - The recipient's address
* @param amount - The amount of tokens to send as a string (e.g., "100.5")
* @returns Promise resolving to the transaction response with hash and details
* @throws Error if insufficient balance, invalid addresses, or transaction fails
*/
sendToken(tokenAddress: string, to: string, amount: string): Promise<TransactionResponse>;
/**
* Gets the transaction receipt for a given transaction hash.
* @param hash - The transaction hash to get the receipt for
* @returns Promise resolving to the transaction receipt or null if not found
* @throws Error if the provider is not set
*/
getTransactionReceipt(hash: string): Promise<TransactionReceipt | null>;
}