OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-wallet commits / b450ff4

Add missing token chain helper functions
Implemented isTokenChain(), getBaseChain(), getTokenInfo(), and TOKEN_CONTRACTS to support ERC-20 token operations. These functions were referenced in wallet-server.cjs but were not defined, causing "is not a function" errors on wallet initialization. Fixes balance, address, and QR code API endpoints for both base chains and tokens. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
b450ff40395e00244fbeb7268baf904f9c7410be
by plankatron <fleeky@gmail.com> · 2026-01-28T23:30:34.000Z

Changed files (1) +66 -1

lib/wdk-integration.cjs +66 -1
……@@ -139,11 +139,76 @@ function walletMnemonicExists() {
139139 return fs.existsSync(WALLET_MNEMONIC_FILE)
140140}
141141
142/**
143 * Token contract addresses for ERC-20 tokens
144 * Format: { 'chain-token': { mainnet: 'address', testnet: 'address' } }
145 */
146const TOKEN_CONTRACTS = {
147 'ethereum-usdt': {
148 mainnet: '0xdac17f958d2ee523a2206206994597c13d831ec7',
149 testnet: '0x7169D38820dfd117C3FA1f22a697dBA58d90BA06' // Sepolia USDT
150 },
151 'ethereum-usdc': {
152 mainnet: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
153 testnet: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238' // Sepolia USDC
154 }
155}
156
157/**
158 * Check if a chain parameter refers to a token (e.g., 'ethereum-usdt')
159 * @param {string} chain - Chain identifier
160 * @returns {boolean}
161 */
162function isTokenChain(chain) {
163 return chain.includes('-') && chain !== 'testnet' && chain !== 'mainnet'
164}
165
166/**
167 * Get base chain from token chain identifier
168 * @param {string} chain - Chain identifier (e.g., 'ethereum-usdt' or 'ethereum')
169 * @returns {string} - Base chain (e.g., 'ethereum')
170 */
171function getBaseChain(chain) {
172 if (!isTokenChain(chain)) {
173 return chain
174 }
175 // Extract base chain from 'ethereum-usdt' -> 'ethereum'
176 return chain.split('-')[0]
177}
178
179/**
180 * Get token contract information
181 * @param {string} chain - Token chain identifier (e.g., 'ethereum-usdt')
182 * @param {boolean} isTestnet - Whether to use testnet contracts
183 * @returns {Object} - Token info { contract, symbol, decimals }
184 */
185function getTokenInfo(chain, isTestnet = true) {
186 const tokenContracts = TOKEN_CONTRACTS[chain]
187 if (!tokenContracts) {
188 throw new Error(`Unsupported token: ${chain}`)
189 }
190
191 const contract = isTestnet ? tokenContracts.testnet : tokenContracts.mainnet
192
193 // Extract token symbol from chain (ethereum-usdt -> USDT)
194 const symbol = chain.split('-')[1]?.toUpperCase() || 'TOKEN'
195
196 return {
197 contract,
198 symbol,
199 decimals: 6 // USDT/USDC use 6 decimals
200 }
201}
202
142203module.exports = {
143204 generateWalletMnemonic,
144205 saveWalletMnemonic,
145206 loadWalletMnemonic,
146207 initializeWDK,
147208 getFirstAddress,
148 walletMnemonicExists
209 walletMnemonicExists,
210 isTokenChain,
211 getBaseChain,
212 getTokenInfo,
213 TOKEN_CONTRACTS
149214}