3

I am trying to create an address for Kusama. Here is my code:

const seed = bip39.mnemonicToSeedSync(WALLET_MNEMONIC, WALLET_PASSWORD);
const privateKeyBuffer = bip32
    .fromSeed(seed)
    .derivePath(`m/44'/434'/0'/0/${accountIndex}`).privateKey; 
const keyring = new Keyring({ss58Format: 2});
return keyring.addFromAddress('0x'+privateKeyBuffer.toString("hex"));

Is that approach true and why my address is:

GUUy9QMLbhotJegAQVyViZUGu6UrohzFcxfNm5nCtF5hKjP

but it is shown as:

5FxsJq4UiEgt8eqEPhgvbmCU8JpF48tooF7uz6opj62ax9yA

at explorer?

3 Answers 3

1

You're probably not using your address in the "Kusama" pane of the polkadot js application (I'm assuming you are using polkadot js).

In practice, the two addresses you've shared belong to the same public key. Are just shown differently because of the network id.

In the polkadot js pane, you can change how the addresses are visualized (i.e. what net-id to use) from 'settings->general->address-prefix'.


Some background you may find useful.

By using subkey tool you can see that both the addresses correspond to the same public key:

❯ subkey inspect 5FxsJq4UiEgt8eqEPhgvbmCU8JpF48tooF7uz6opj62ax9yA
Public Key URI `5FxsJq4UiEgt8eqEPhgvbmCU8JpF48tooF7uz6opj62ax9yA` is account:
Network ID/version: substrate
Public key (hex):   0xac7d46c501e44622a0fc27cca4e0dafff4dbc098e346478788493395e603852b
Account ID:         0xac7d46c501e44622a0fc27cca4e0dafff4dbc098e346478788493395e603852b
SS58 Address:       5FxsJq4UiEgt8eqEPhgvbmCU8JpF48tooF7uz6opj62ax9yA

❯ subkey inspect GUUy9QMLbhotJegAQVyViZUGu6UrohzFcxfNm5nCtF5hKjP
Public Key URI `GUUy9QMLbhotJegAQVyViZUGu6UrohzFcxfNm5nCtF5hKjP` is account:
Network ID/version: kusama
Public key (hex):   0xac7d46c501e44622a0fc27cca4e0dafff4dbc098e346478788493395e603852b
Account ID:         0xac7d46c501e44622a0fc27cca4e0dafff4dbc098e346478788493395e603852b
SS58 Address:       GUUy9QMLbhotJegAQVyViZUGu6UrohzFcxfNm5nCtF5hKjP

What is different is the network-id. You can manually check the network id of an Address by converting it from base 58 to hex (e.g. using this website):

b58: 5FxsJq4UiEgt8eqEPhgvbmCU8JpF48tooF7uz6opj62ax9yA
hex: 2a ac7d46c501e44622a0fc27cca4e0dafff4dbc098e346478788493395e603852b 8861

b58: GUUy9QMLbhotJegAQVyViZUGu6UrohzFcxfNm5nCtF5hKjP
hex: 02 ac7d46c501e44622a0fc27cca4e0dafff4dbc098e346478788493395e603852b cea2

From the decoded hex, you can see that the address is just the concatenation of three elements: NetworkId ++ PublicKey ++ Checksum

What changes between the two AccountId you've provided is just the network id (0x02 for Kusama, 0x2a for Generic-Substrate) and the checksum (because the network id is different).

1

Yes, the approach is correct. Your confusion comes from the way your explorer is defaulting to a Polkadot address.

All accounts for different Substrate based chains use the SS58 format. This means a single 256-bit public key can represent a range of different chain-specific account addresses. UIs just need to convert it according to what chain a user wants to interact with.

Have a look at this tool to see what different addresses would look like for your example.

0

With "at explorer" I believe you mean in something like the polkadot-js apps UI?

In that case, the configuration for the display is based on your settings. The ss58prefix is for display purposes only. When you use ss58Format: 2 in your keyring, that instructs the keyring to display any address using that format. It doesn't and cannot apply externally to the keyring.

Any additional explorer-like application where you use the address will use the format as specified by the chain (for development chains this is 42), unless specifically overridden.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.