board-coin-sdk
v0.1.0
Published
SDK for interacting with Phi Board Coin protocol
Maintainers
Readme
Board Coin SDK
A TypeScript SDK for interacting with the Phi Protocol, enabling seamless integration with board tokens, trading, and FusedETH operations.
Features
- 🪙 Board Token Management
- 💱 Trading Operations
- 🔄 FusedETH Integration
- 🔍 Metadata Handling
- 🔐 Secure Contract Interactions
- ⚠️ Comprehensive Error Handling
Installation
npm install board-coin-sdk
# or
yarn add board-coin-sdkQuick Start
import { PhiClient } from "board-coin-sdk";
import { createPublicClient, createWalletClient, http } from "viem";
import { mainnet } from "viem/chains";
// Initialize the client
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
});
const walletClient = createWalletClient({
chain: mainnet,
transport: http(),
});
const phiClient = new PhiClient({
publicClient,
walletClient,
chain: mainnet,
});
// Example: Get board token metadata
try {
const boardMetadata = await phiClient.getBoardMetadata(boardAddress);
console.log("Board metadata:", boardMetadata);
} catch (error) {
if (error instanceof ValidationError) {
console.error("Invalid input:", error.message);
} else if (error instanceof ContractError) {
console.error("Contract interaction failed:", error.message);
} else if (error instanceof NetworkError) {
console.error("Network error:", error.message);
} else {
console.error("Unexpected error:", error);
}
}Core Functionality
Board Token Operations
The SDK provides comprehensive functionality for managing board tokens:
- Get board token metadata
- View token balances
- Transfer tokens
- Manage allowances
- Cross-chain operations
Trading
Execute trades with board tokens:
try {
// Buy board tokens
const buyResult = await phiClient.buyBoard({
boardAddress: "0x...",
amount: BigInt(1000000),
maxPrice: BigInt(1000000),
});
console.log("Buy successful:", buyResult);
// Sell board tokens
const sellResult = await phiClient.sellBoard({
boardAddress: "0x...",
amount: BigInt(1000000),
minPrice: BigInt(1000000),
});
console.log("Sell successful:", sellResult);
} catch (error) {
if (error instanceof AllowanceError) {
console.error("Allowance error:", error.message);
} else if (error instanceof TransactionError) {
console.error("Transaction failed:", error.message);
} else if (error instanceof ContractError) {
console.error("Contract error:", error.message);
} else {
console.error("Unexpected error:", error);
}
}FusedETH Integration
Manage FusedETH operations:
- Deposit ETH
- Withdraw ETH
- View balances
- Monitor yield
Error Handling
The SDK provides comprehensive error handling with custom error classes for different types of errors:
Error Classes
PhiSDKError: Base error class for all SDK errorsWalletClientError: Thrown when wallet client is not configuredContractError: Thrown when contract interaction failsValidationError: Thrown when input validation failsMetadataError: Thrown when token metadata parsing failsTransactionError: Thrown when transaction failsNetworkError: Thrown when network/chain operations failAllowanceError: Thrown when allowance operations failPriceError: Thrown when price operations fail
Error Handling Example
import {
PhiSDKError,
WalletClientError,
ContractError,
ValidationError,
MetadataError,
TransactionError,
NetworkError,
AllowanceError,
PriceError
} from 'board-coin-sdk';
try {
// Your SDK operation here
await phiClient.buyBoard({...});
} catch (error) {
if (error instanceof ValidationError) {
// Handle invalid input
console.error('Invalid input:', error.message);
} else if (error instanceof WalletClientError) {
// Handle missing wallet client
console.error('Wallet not connected:', error.message);
} else if (error instanceof ContractError) {
// Handle contract interaction errors
console.error('Contract error:', error.message);
if (error.originalError) {
console.error('Original error:', error.originalError);
}
} else if (error instanceof TransactionError) {
// Handle transaction failures
console.error('Transaction failed:', error.message);
console.error('Transaction hash:', error.txHash);
} else if (error instanceof NetworkError) {
// Handle network issues
console.error('Network error:', error.message);
} else if (error instanceof AllowanceError) {
// Handle allowance issues
console.error('Allowance error:', error.message);
} else if (error instanceof PriceError) {
// Handle price-related errors
console.error('Price error:', error.message);
} else if (error instanceof PhiSDKError) {
// Handle other SDK errors
console.error('SDK error:', error.message);
} else {
// Handle unexpected errors
console.error('Unexpected error:', error);
}
}API Reference
PhiClient
The main client class for interacting with the protocol.
Constructor
new PhiClient(config: PhiSdkConfig)Configuration options:
publicClient: Viem PublicClient instancewalletClient: Optional Viem WalletClient instancechain: Chain configuration
Methods
getBoardMetadata(address: Address): Get metadata for a board tokengetBoardPrice(address: Address): Get current price of a board tokenbuyBoard(params: TradeParams): Buy board tokenssellBoard(params: TradeParams): Sell board tokensgetPhiToken(): Get PHI token contract instancegetFusedETH(): Get FusedETH contract instance
Types
The SDK exports various TypeScript types for type safety:
PhiSdkConfig: Configuration for the SDK clientBoardToken: Board token metadata structureTradeParams: Parameters for trading operationsTradeResult: Result of trading operations
Security
- All contract interactions are handled through the Viem library
- Proper error handling and type safety
- Support for various wallet providers
- Secure transaction signing
- Input validation for all operations
- Comprehensive error handling with detailed error messages
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
