-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to convert cosmos public key to ethereum address? #1044
Comments
What exactly do you mean @chismo950 ? Cosmos public keys aren't related to Ethereum addresses. |
This is very well possible. It is probably big hackery and should not be done, but it can be done. Like Ethereum, Cosmos SDK uses secp256k1 keypairs. So you can (not should) use an Ethereum keypair for a Cosmos chain and vice versa. The biggest difference is that Ethereum uses uncompressed secp256k1 pubkeys and Cosmos uses compressed secp256k1 pubkeys. The steps are as follows:
Point 4 is out of scope for CosmJS but the rest can be done with the general purpose tooling you find here. |
Thank you very much, I did it! |
Hi. Is there a way to convert from eth address to cosmos chain address in Go? I tried several ways but my imported wallet from eth not match with the one I convert on chains like osmosis, cosmos, nolus, and it match with evmos and dym. Do you know why? Is it because evmos and dym impl evm module? |
Ethereum uses different HD path ( Please do not use this in production. ❌ |
The chain itself does not care which derivation path you use. In fact it can't even know where the derived keypair is coming from. The problem you will have though is compatibility with other wallets. |
@webmaster128 is correct, the chain itself doesn't care. You can generate a private key with any coin type and use it, chains just usually have a canonical coin type so that things don't interfere, but once you have the Private Key it doesn't matter, the chain just cares if things are signed with the right private keys. You can see this in action on Sei. If you take your seed from Metamask and put it into a Sei Cosmos wallet like Compass it give a different wallet address than metamask due to it generating a coin type 118 private key from the mnemonic where Metamask generated a coin type 60 Private Key. Now if instead of exporting the seed from Metamask, you export the private key, you will see the addresses do in fact match. This is because the Private Key was generated specifically for coin type 60 by Metamask and then Compass can pick it up and use it just fine. |
You can derive addresses the "Ethereum way" and the "Cosmos way" because in both cases the addresses are just derived from the pubkey, which comes from the private key, which comes from the HD path of the mnemonic. |
Thanks @webmaster128 @codebycarson for the clarification. I have a couple more questions:
|
It's the same for both Ethereum and Cosmos. You don't need to use HD derivation at all and can just have a raw private and public secp256k1 key.
Two paths just give you two different private keys, two different public keys, two different addresses. So completely independent accounts from the perspective of the chain. |
use @cosmjs/crypto?
The text was updated successfully, but these errors were encountered: