Skip to content

Conversation

@moliholy
Copy link
Collaborator

@moliholy moliholy commented Aug 15, 2025

Closes #566

This PR adds the convert command to initially convert from Ethereum address format to Substrate address format and viceversa.

However, and merely as a proposal, I think this command should be a gateway to the same (or more!) functionality as the one we can find in the Substrate js-utilities.

Also, this convert command could be perfectly isolated as a separate feature. Would be fine for me to address that, but firstly it'd be good go have some feedback.

EDIT: the command has been isolated in a separate feature called convert, which has been included under the experimental feature's umbrella.

Usage

pop convert address --help                                       
Convert an Ethereum address into a Substrate address and vice versa

Usage: pop convert address <ADDRESS> [PREFIX]

Arguments:
  <ADDRESS>  The Substrate or Ethereum address
  [PREFIX]   The SS58 prefix. Defaults to 0 (Polkadot).

Options:
  -h, --help  Print help
# Convert from Substrate address to Ethereum address:
pop convert address 13dKz82CEiU7fKfhfQ5aLpdbXHApLfJH5Z6y2RTZpRwKiNhX
0x742d35cc6634c0532925a3b844bc454e4438f44e
# Convert from Ethereum address to Substrate address with prefix 0 (Polkadot).
pop convert address 0x742d35Cc6634C0532925a3b844Bc454e4438f44e          
13dKz82CEiU7fKfhfQ5aLpdbXHApLfJH5Z6y2RTZpRwKiNhX
# Convert from Ethereum address to Substrate address with prefix 42 (Generic).
pop convert address 0x742d35Cc6634C0532925a3b844Bc454e4438f44e 42   
5Eh2qnm8NwCeDnfBhm2aCfoSffBAeMk914NUs8UDGLuoY6qg

@AlexD10S AlexD10S self-requested a review August 28, 2025 08:10
Copy link
Collaborator

@AlexD10S AlexD10S left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent job! I really like the feature, I believe it will be widely used. The DevEx is very smooth, the user doesn’t have to specify the input format, the CLI already recognizes it.
The code is solid and is well tested. The only comment I left was about the new library that was imported, which might not be necessary.

I do have one question from testing: when I try with Alice’s address

pop convert address 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY

I get the following error:

Error: Invalid address: last 12 bytes must be 0xEE

@moliholy
Copy link
Collaborator Author

moliholy commented Aug 28, 2025

I do have one question from testing: when I try with Alice’s address

pop convert address 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
I get the following error:

Error: Invalid address: last 12 bytes must be 0xEE

The reason it does not work with Alice's public key is because the operation is not reversible. If you recalculate the Polkadot address out of the resulting 20 bytes the account would be different, since Alice's public key bytes does not end in 0xeeeeeeeeeeeeeeeeeeeeeeee.

We could threat this differently, of course. I have no strong opinion on this, so up to you to decide.

@moliholy
Copy link
Collaborator Author

moliholy commented Aug 28, 2025

@AlexD10S some minor detail regarding this development:

Screenshot 2025-08-29 at 00 23 20

The output, as you can see, is not purely the resulting address (meaning that it contains the formatting sugar of the cli.success function). For this very particular case (and hashing, since we are on it) in my opinion the output should be totally clean, similar to the result of an standard println! statement. Otherwise, results cannot be piped, hence making life harder when integrating pop-cli in shell scripts.

I didn't do it here, as I wanted to respect the similar development for hashing, but it might be worth creating an issue so that this does not get forgotten.

@AlexD10S
Copy link
Collaborator

I didn't do it here, as I wanted to respect the similar development for hashing, but it might be worth creating an issue so that this does not get forgotten.

Good point, it makes sense to keep the println! for the output as you suggested. Feel free to go ahead and create the issue.

Another option would be to move the address conversion method into the pop-common crate and expose it, so that third-party applications integrating with our crates can also reuse it.

@AlexD10S AlexD10S self-requested a review August 29, 2025 12:33
@moliholy
Copy link
Collaborator Author

Good point, it makes sense to keep the println! for the output as you suggested. Feel free to go ahead and create the issue.

@AlexD10S done, see #601.

Another option would be to move the address conversion method into the pop-common crate and expose it, so that third-party applications integrating with our crates can also reuse it.

Absolutely! Moving utility stuff to a library seems like a very good idea.

@moliholy moliholy self-assigned this Sep 2, 2025
@moliholy moliholy force-pushed the feat/convert-addresses branch 2 times, most recently from b66c9ea to bdde384 Compare September 2, 2025 21:32
@AlexD10S AlexD10S self-requested a review September 3, 2025 06:46
@moliholy moliholy force-pushed the feat/convert-addresses branch from 12d6a04 to 4434dc6 Compare September 3, 2025 07:55
@codecov
Copy link

codecov bot commented Sep 3, 2025

Codecov Report

❌ Patch coverage is 85.22727% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.08%. Comparing base (607512e) to head (49ff1a8).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
crates/pop-cli/src/commands/convert.rs 86.48% 7 Missing and 3 partials ⚠️
crates/pop-cli/src/commands/mod.rs 78.57% 3 Missing ⚠️
@@            Coverage Diff             @@
##             main     #592      +/-   ##
==========================================
- Coverage   79.36%   77.08%   -2.29%     
==========================================
  Files         106      109       +3     
  Lines       25979    24854    -1125     
  Branches    25979    24854    -1125     
==========================================
- Hits        20619    19158    -1461     
- Misses       3073     3697     +624     
+ Partials     2287     1999     -288     
Files with missing lines Coverage Δ
crates/pop-cli/src/commands/mod.rs 70.04% <78.57%> (-0.14%) ⬇️
crates/pop-cli/src/commands/convert.rs 86.48% <86.48%> (ø)

... and 27 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AlexD10S AlexD10S self-requested a review September 3, 2025 09:11
Copy link
Collaborator

@AlexD10S AlexD10S left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀
One follow-up: we’ll also need to document this new command in the docs repo: https://github.com/r0gue-io/pop-docs

@AlexD10S AlexD10S merged commit 1c685ac into r0gue-io:main Sep 3, 2025
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(utils): add utility to convert Ethereum (H160) address to Substrate (SS58) address

2 participants