Within this document, we'll outline some examples on how to convert addresses between different formats in Titan Chain.
Convert Hex <> Bech32 address
Titan Chain addresses are compatible with both Ethereum addresses (hex format) and Cosmos addresses (bech32 format). You can convert between the two formats easily using the same private key.
Key Classes Overview
PrivKeySecp256k1 Class
The PrivKeySecp256k1 class handles private key operations:
exportclassPrivKeySecp256k1{ // Generate a random private keystaticgenerateRandomKey():PrivKeySecp256k1; // Create from Uint8Arrayconstructor(protectedreadonlyprivKey:Uint8Array); // Convert to bytestoBytes():Uint8Array; // Get corresponding public keygetPubKey():PubKeySecp256k1; // Sign a 32-byte digestsignDigest32(digest:Uint8Array):{readonly r:Uint8Array;readonly s:Uint8Array;readonly v:number|null;};}
PubKeySecp256k1 Class
The PubKeySecp256k1 class handles public key operations and address generation:
Using TypeScript
You can easily convert between a Titan address and Ethereum address by using our utility functions:
Convert ETH Address to Titan Bech32
For chains using ETH-style addressing with bech32 encoding (slip44 = 60):
Generate Random Key and Addresses
Create a new random private key and generate all address formats:
Multi-chain Address Generation
Generate addresses for multiple chains using the same private key:
Signing and Verification
Sign and verify messages using the secp256k1 curve:
Key Differences
ETH addressing: Uses uncompressed public key + keccak256 hash