Lädt...


🔧 Get wallet address for multiple chains in cosmos app chains


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

In the Cosmos ecosystem, each chain has its own specific prefix for Bech32 addresses. When you connect your Keplr wallet to a Cosmos SDK-based chain, you receive a wallet address specific to that chain. However, the underlying public key remains the same across these chains, and you can derive the addresses for other chains by converting the address prefix.

Here's how you can derive the address for multiple chains using JavaScript, assuming you have the wallet address for one chain:

  1. Extract the Public Key: You need the public key associated with the address. This step typically involves interacting with the Keplr wallet to get the public key.

  2. Convert the Address Prefix: Use the Bech32 encoding library to convert the address prefix to the desired chain's prefix.

Show me the code

Below is an example using JavaScript and the bech32 library to convert an address from the Osmosis chain to the Stargaze chain:

  • Install the necessary libraries:
npm install @cosmjs/encoding @cosmjs/crypto
  • JavaScript code to convert the address prefix:
const { Bech32 } = require('@cosmjs/encoding');

/**
 * Converts a Bech32 address to another Bech32 address with a different prefix.
 * @param {string} address - The original Bech32 address.
 * @param {string} newPrefix - The new prefix for the Bech32 address.
 * @returns {string} - The new Bech32 address with the specified prefix.
 */
function convertAddressPrefix(address, newPrefix) {
    const { prefix, data } = Bech32.decode(address);
    return Bech32.encode(newPrefix, data);
}

// Example usage
const osmosisAddress = 'osmo1n3v7hdf3lj6gr7hyluq7x4hj4snmajsze3fnlq';
const stargazePrefix = 'stars';

const stargazeAddress = convertAddressPrefix(osmosisAddress, stargazePrefix);
console.log('Stargaze Address:', stargazeAddress);

This code will convert an Osmosis address to a Stargaze address by changing the Bech32 prefix.

Summary

By extracting the public key from Keplr and using a Bech32 conversion, you can derive addresses for multiple chains in the Cosmos ecosystem. This approach leverages the shared public key across these chains and the flexibility of Bech32 encoding.

Thanks for your time. Happy coding!

...

🔧 Get wallet address for multiple chains in cosmos app chains


📈 75.88 Punkte
🔧 Programmierung

📰 Google Wallet: Benachrichtigungen werden in die Wallet-App verschoben – kommen jetzt aus anderer Quelle


📈 24.95 Punkte
📰 IT Nachrichten

📰 Biden Signs Executive Order To Address Chip Shortage Through a Review To Strengthen Supply Chains


📈 22.44 Punkte
📰 IT Security Nachrichten

📰 ESR HaloLock Wallet Stand hands-on: Multi-card wallet and adjustable stand for the iPhone


📈 21.97 Punkte
📰 IT Nachrichten

📰 What Is a Crypto Wallet and How to Keep Your Wallet Secure?


📈 21.97 Punkte
📰 IT Security Nachrichten

📰 Best bitcoin hardware wallet: Choosing the right wallet for your cryptocurrency


📈 21.97 Punkte
📰 IT Nachrichten

🔧 Saksh Easy Wallet: Secure and Flexible Wallet Management for Node.js


📈 21.97 Punkte
🔧 Programmierung

🕵️ TronLink Wallet 2.2.0 Secure Storage <wallet-name>.xml privilege escalation


📈 21.97 Punkte
🕵️ Sicherheitslücken

🔧 Solana: Wallet adapter for a web based wallet


📈 21.97 Punkte
🔧 Programmierung

📰 Digital Wallet E-Wallet Payment System and How It Works


📈 21.97 Punkte
🤖 Android Tipps

📰 Proton Wallet: Einfach zu bediendendes Bitcoin-Wallet vorgestellt


📈 21.97 Punkte
📰 IT Nachrichten

📰 EUDI Wallet: A wallet full of loopholes


📈 21.97 Punkte
📰 IT Nachrichten

📰 Shitcoin Wallet Extension Isn’t A Crypto Wallet But A Crypto Stealer


📈 21.97 Punkte
📰 IT Security Nachrichten

📰 Google Wallet unterstützt endlich Datenformat von Apple Wallet – erreicht jetzt immer mehr Nutzer


📈 21.97 Punkte
🤖 Android Tipps

🕵️ Shitcoin Wallet Chrome extension steals crypto-wallet private keys and passwords


📈 21.97 Punkte
🕵️ Hacking

📰 Cryptocurrency wallet CEO loses $125,000 in wallet-draining scam


📈 21.97 Punkte
📰 IT Security Nachrichten

📰 Designer Wallet or Mobile Wallet: Which One Do You Carry?


📈 21.97 Punkte
📰 IT Security Nachrichten

🍏 HaloLock Power Bank Wallet for iPhone combines a battery, a wallet, and a stand in one accessory


📈 21.97 Punkte
🍏 iOS / Mac OS

📰 Designer Wallet or Mobile Wallet: Which One Do You Carry?


📈 21.97 Punkte
📰 IT Security Nachrichten

🍏 Veci 2-in-1 MagSafe Wallet review: Best MagSafe Wallet that isn't Apple's


📈 21.97 Punkte
🍏 iOS / Mac OS

🍏 ESR Geo Wallet review: The only Find My-enabled MagSafe wallet holds its own


📈 21.97 Punkte
🍏 iOS / Mac OS

📰 Krypto Wallet erstellen: So richten Sie eine Wallet ein


📈 21.97 Punkte
🖥️ Betriebssysteme

📰 What 'Ad Astra' and Brad Pitt Get Wrong About Space Travel, Science and Life In the Cosmos


📈 19.98 Punkte
📰 IT Security Nachrichten

📰 Clipper malware on Play Store replaces users BTC & ETH wallet address


📈 19.96 Punkte
📰 IT Security Nachrichten

🔧 Generating Taproot Wallet Address using bitcoinjs-lib


📈 19.96 Punkte
🔧 Programmierung

matomo