Function: hexStringExtractionAndNormalization()
Gala Launchpad SDK 9.0.0-rc.5 / index / hexStringExtractionAndNormalization
Function: hexStringExtractionAndNormalization()
hexStringExtractionAndNormalization(
addressLike):string|null
Defined in: packages/launchpad-sdk/dist/utils/string-patterns.d.ts:343
Extract and normalize hex address from pipe-delimited format.
Parses addresses in formats like 'eth|1234...' or plain '0x...' formats and returns the hex portion. Returns null if format is invalid or no hex found.
Consolidated from 6 duplicated patterns in address extraction:
const [chain, address] = addressLike.split('|')- Manual hex extraction and validation
Parameters
addressLike
string
Address string in 'chain|0xhex' or '0xhex' format
Returns
string | null
Hex address portion (without '0x' prefix), or null if invalid
Examples
Basic hex extraction
import { hexStringExtractionAndNormalization } from '@gala-chain/launchpad-sdk';
const ethAddress = 'eth|1234567890abcdef1234567890abcdef12345678';
const hex = hexStringExtractionAndNormalization(ethAddress);
console.log(hex); // '1234567890abcdef1234567890abcdef12345678'
const plainHex = '0xabcdef0123456789abcdef0123456789abcdef01';
const result = hexStringExtractionAndNormalization(plainHex);
console.log(result); // 'abcdef0123456789abcdef0123456789abcdef01'
GSwap user asset lookup
import { hexStringExtractionAndNormalization } from '@gala-chain/launchpad-sdk';
const walletAddress = 'eth|1234567890abcdef...';
const hexOnly = hexStringExtractionAndNormalization(walletAddress);
if (hexOnly) {
const assets = await gswapService.getUserAssets(`eth|${hexOnly}`);
}
Error handling for invalid format
import { hexStringExtractionAndNormalization } from '@gala-chain/launchpad-sdk';
const invalidAddress = 'not-an-address';
const hex = hexStringExtractionAndNormalization(invalidAddress);
if (hex === null) {
console.error('Invalid address format');
}
Client-side address handling
import { hexStringExtractionAndNormalization } from '@gala-chain/launchpad-sdk';
const address = 'client|mongo-id-12345';
const hex = hexStringExtractionAndNormalization(address);
// For non-hex formats, returns null
if (hex === null) {
// Not a hex address, handle differently
}
Since
6.14.0