A quick demo CLI demonstrating the Tetherto WDK (Wallet Development Kit) for multi-chain cryptocurrency wallet functionality.
- Multi-chain wallet management using a single seed phrase
- OOP library architecture with reusable wallet and API classes
- Automatic wallet persistence with local file storage
- Balance checking for native tokens (MATIC)
- Transaction sending with fee estimation and confirmation tracking
- Transaction history via WDK Indexer API for token transfers
- Support for Polygon (easily extensible to Ethereum, Base, Tron, Bitcoin, etc.)
npm installCreate a .wallet file with your 12-word seed phrase:
echo "your twelve word seed phrase goes here like this example phrase" > .walletCreate a .wdk-api-key file with your API key from Tether WDK:
echo "your-api-key-here" > .wdk-api-keyCheck your balance:
npm run balanceSend a transaction:
npm run sendGet transaction history:
npm run check| Command | Description |
|---|---|
npm run balance |
Check Polygon MATIC balance |
npm run send |
Send a transaction on Polygon |
npm run check |
Get USDT transaction history from WDK Indexer API |
The project uses a modular OOP library architecture for reusability and maintainability:
WalletManager (Base class)
- Core wallet operations for any blockchain
- Seed phrase loading and management
- WDK initialization and wallet registration
- Account access with caching
- Methods:
getAddress(),getBalance(),getNetworkInfo(),quoteTransaction(),sendTransaction(),waitForTransaction() - Static utility:
formatBalance()for wei/token conversion
PolygonWallet (Specialized class)
- Pre-configured for Polygon network
- Extends
WalletManagerwith Polygon-specific defaults - Returns formatted balance objects
- Includes
getExplorerUrl()for PolygonScan links
ApiClient (Base class)
- Generic REST API client with GET/POST methods
- Centralized response handling
- Structured error handling
WdkApiClient (Specialized class)
- Pre-configured for WDK Indexer API (
https://wdk-api.tether.io) - Automatic API key management from
.wdk-api-keyfile - Methods:
getTokenTransfers(),getTokenBalances(),health() - Factory method:
fromFile()for easy instantiation
ApiError (Custom error class)
- Structured API error handling with status codes
- Helper methods:
isRateLimitError(),isAuthError(),isNotFoundError()
check-polygon.js: Check Polygon MATIC balance usingPolygonWalletsend-transaction.js: Send transactions on Polygon with fee estimation and confirmationget-transactions.js: Fetch USDT transaction history usingWdkApiClient
import { PolygonWallet } from "./lib/WalletManager.js";
const wallet = new PolygonWallet();
wallet.initialize();
const balance = await wallet.getBalance();
console.log(`${balance.formatted} ${balance.token}`);import { PolygonWallet } from "./lib/WalletManager.js";
const wallet = new PolygonWallet();
wallet.initialize();
const address = await wallet.getAddress();
// Send 0.001 MATIC to self
const result = await wallet.sendTransaction({
to: address,
value: 1000000000000000n // 0.001 MATIC in wei
});
console.log(`Transaction: ${wallet.getExplorerUrl(result.hash)}`);
// Wait for confirmation
const receipt = await wallet.waitForTransaction(result.hash);
console.log(`Confirmed in block ${receipt.blockNumber}`);import { PolygonWallet } from "./lib/WalletManager.js";
import { WdkApiClient } from "./lib/ApiClient.js";
const wallet = new PolygonWallet();
wallet.initialize();
const apiClient = WdkApiClient.fromFile();
const address = await wallet.getAddress();
const transfers = await apiClient.getTokenTransfers('polygon', 'usdt', address, {
limit: 20,
offset: 0
});
console.log(`Found ${transfers.data.length} transactions`);To add support for another blockchain (e.g., Ethereum):
import { WalletManager } from "./lib/WalletManager.js";
import WalletManagerEvm from "@tetherto/wdk-wallet-evm";
export class EthereumWallet extends WalletManager {
constructor(options = {}) {
super(options);
this.chainId = "ethereum";
this.provider = options.provider || "https://eth.llamarpc.com";
this.nativeToken = "ETH";
}
initialize() {
super.initialize();
this.registerWallet(this.chainId, WalletManagerEvm, {
provider: this.provider
});
return this;
}
async getAddress() {
return super.getAddress(this.chainId);
}
async getBalance() {
const balance = await super.getBalance(this.chainId);
return {
wei: balance,
formatted: WalletManager.formatBalance(balance, 18, 6),
token: this.nativeToken
};
}
// ... other methods similar to PolygonWallet
}- The
.walletfile contains your private seed phrase - keep it secure and never share it - The
.wdk-api-keyfile contains your API key - do not commit to version control - Both files are in
.gitignoreby default - Use authenticated/private RPC endpoints for production applications
- The sample uses public RPC endpoints for demonstration purposes
.
├── lib/
│ ├── WalletManager.js # Wallet management classes
│ ├── ApiClient.js # API client classes
│ └── index.js # Central exports
├── check-polygon.js # Balance checker script
├── send-transaction.js # Transaction sender script
├── get-transactions.js # Transaction history script
├── package.json # Dependencies and npm scripts
├── .wallet # Seed phrase (gitignored)
├── .wdk-api-key # WDK API key (gitignored)
├── CLAUDE.md # Developer guidance
└── README.md # This file
ISC