I have a public key in HEX into. How do I get the SS58 representation of it? Is there a command line tool?
3 Answers
The easiest way is to use the subkey
tool. You can install it from the substrate repo.
Then, you can use:
$ subkey inspect --public 0xec7c1c10c73a2d90c6a4fc92a5212caaff849a65193db3a2b2aa1ffdadb99f06
Network ID/version: substrate
Public key (hex): 0xec7c1c10c73a2d90c6a4fc92a5212caaff849a65193db3a2b2aa1ffdadb99f06
Account ID: 0xec7c1c10c73a2d90c6a4fc92a5212caaff849a65193db3a2b2aa1ffdadb99f06
Public key (SS58): 5HQn2URwTz6CPsZzbtPzm93KEza881uQ92rLRhtRzSLoA7ws
SS58 Address: 5HQn2URwTz6CPsZzbtPzm93KEza881uQ92rLRhtRzSLoA7ws
Be aware, that the SS58 depends on the network, so it might be possible that you need to specify it via the --network
command line argument.
Subalfred is another option now.
It provides more detail about the key.
It could:
- show the SS58 prefix
- detect if it is a pallet account
- detect if it is a paraid
- show all networks' address
- accept multiple type of input, public key/address/id
subalfred key --show-prefix --list-all 0x6d6f646c70792f74727372790000000000000000000000000000000000000000
public-key 0x6d6f646c70792f74727372790000000000000000000000000000000000000000 PalletId(py/trsry)
BareEd25519 3 LqU5wxzkNSKtMmvyXtM6vimZUPuH1mhTaTHm9L1h4BA6stP
BareSecp256k1 43 5LKrRdd881RQ8hxVCq5JCyMmQt7fULxX1CcYNV44DFxfMrsn
BareSr25519 1 9G9ZxtByngsaEy1AU8JM8BvGW7KAeWf5hM2Xn3QmLzBY97T
DICO 53 6LCT1Z39xvAfhJ18G9sXyz21sjYc2BFitc9rXKV4qouYBA7Z
Eggnet 4006 oVPveLKWsFc9HzQiHqDv81ecYWEH8EyHSGDCwMNVNTJeQQxFU
ICE 2208 npP7jGQpDyrB6vTXuh3wqNJdPoWN9nK5vWSbbo82eQy9kNdXb
KICO 52 6EQnkZVkadHwYEbfMczWc5kbEFQJxzdChfbiudqmNxK3tnhx
SNOW 2207 nhzjWivARPECavheDiyeKCdcCSTDLGancSF9CRNsNnF6YMzYq
Turing 2114 cU77QDyYhsYaVKKm8p5Ywh4gygQ59bm2dhsoiZB1JtoxHGyQR
acala 10 23M5ttkpSQZQymcBKG3WkEak5sPxfJBLnALD4vq7w3La53HJ
...
I recommend using Shawn Tabrizi Substrate-js utilities
or either coding using the hex_literal crate.
pub const Bob: AccountId = AccountId::from(
hex_literal::hex!("8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48")
);
However, while coding in Substrate, I advice trying to migrate your logic directly to ss58
instead of working with hex
keys. Will make your days easier. e.g. below:
pub const Bob: AccountId = AccountId::from_ss58check("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty").unwrap();
-
Can you please elaborate on the substrate answer? I get an function or associated item not found in
AccountId32
. Dec 27, 2022 at 9:55