overview
Provider Architecture
Core Provider Interface
All providers implement the IProviderAdapter interface:
interface IProviderAdapter {
// Transaction operations
sendTransaction(params: TransactionParams): Promise<string>;
call(params: CallParams): Promise<any>;
estimateGas(params: GasEstimationParams): Promise<bigint>;
// Account operations
getBalance(address: string): Promise<bigint>;
getAccount(): Promise<string>;
signMessage(message: string): Promise<string>;
// Network operations
getChainId(): Promise<number>;
getBlockNumber(): Promise<bigint>;
getTransactionReceipt(hash: string): Promise<TransactionReceipt>;
// Contract operations
getContract(address: string, abi: any): any;
getLogs(filter: LogFilter): Promise<Log[]>;
// Utility operations
parseEvents(receipt: TransactionReceipt, abi: any): ParsedEvent[];
waitForTransaction(hash: string): Promise<TransactionReceipt>;
}
Available Providers
1. Viem Provider (Recommended)
Modern, type-safe provider with excellent TypeScript support:
import { ViemProviderAdapter } from 'tokenops-sdk';
import { createPublicClient, createWalletClient, http } from 'viem';
import { mainnet } from 'viem/chains';
const publicClient = createPublicClient({
chain: mainnet,
transport: http('YOUR_RPC_URL')
});
const walletClient = createWalletClient({
chain: mainnet,
transport: http('YOUR_RPC_URL'),
account: 'YOUR_ACCOUNT'
});
const provider = new ViemProviderAdapter(publicClient, walletClient);
2. Ethers Provider
Not yet supported
Migration Guide
From Ethers.js to Viem
// Before (Ethers.js)
const provider = new ethers.JsonRpcProvider(RPC_URL);
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
const ethersAdapter = new EthersProviderAdapter(wallet);
// After (Viem)
const publicClient = createPublicClient({
chain: mainnet,
transport: http(RPC_URL)
});
const walletClient = createWalletClient({
chain: mainnet,
transport: http(RPC_URL),
account: privateKeyToAccount(PRIVATE_KEY)
});
const viemAdapter = new ViemProviderAdapter(publicClient, walletClient);