0

I'm trying to figure out the relations of the various types of addresses and how to convert one into the other.

The Nami wallet returns from its method cardano.getUsedAddresses() an array with one address that is 114 characters long and looks like this (testnet):

00dc107d6faf3fccbfae8b7446e3703f30200c7ae2767e607c88608a90c0efa54fe993c0f2de5236b46deaa4bc34b36c7c388f53eb51c9885a

This string is apparently the representation of the so called BaseAddress.

Now, I figured out that this format is the concatenation of three parts:

  1. two characters for the network. '00' for testnet and '01' for the main net
  2. A hex encoded 56 characters long hash of the verification key
  3. A hex encoded 56 characters long hash of the staking key

So, I extracted the verification key hash and converted it into the bech32 format (elixir code):

pkh_hex = "dc107d6faf3fccbfae8b7446e3703f30200c7ae2767e607c88608a90"
bytes = Base.decode16!(pkh_hex, case: :lower)
bech_string = Bech32.encode("addr_vkh", bytes)

This gives me the value addr_vkh1msg86ma08lxtlt5tw3rwxuplxqsqc7hzwelxqlygvz9fq6dx76x for bech_string which corresponds to the one confirmed by the converter here: https://input-output-hk.github.io/cardano-addresses/demo

The address shown on the receive screen of the Nami wallet is (testnet):

addr_test1qrwpqlt04ulue0aw3d6ydcms8uczqrr6ufm8ucru3psg4yxqa7j5l6vncredu53kk3k74f9uxjekclpc3af7k5wf3pdqtk6tn9

I am wondering:

A. How can I derive this last address string above from the base address ?

B. Also, how can I convert the addr_vkh-address into a addr-address (of course without the staking key part) ?

C. Is this verification key hash the thing that is called PaymentPubKeyHash in Plutus ?

1 Answer 1

1

A. The "last address" and "base address" described above are the exact same data in different representations. What you're calling the "base address" is the hex representation of an address. The bech32 representation is just an encoding of that same data. The bech32 CLI utility is really good for doing these conversions (although the nodejs one you reference above can be used as well)

bech32 addr_test <<< 00dc107d6faf3fccbfae8b7446e3703f30200c7ae2767e607c88608a90c0efa54fe993c0f2de5236b46deaa4bc34b36c7c388f53eb51c9885a
addr_test1qrwpqlt04ulue0aw3d6ydcms8uczqrr6ufm8ucru3psg4yxqa7j5l6vncredu53kk3k74f9uxjekclpc3af7k5wf3pdqtk6tn9

B. The easiest way to understand address formats is at the binary level. You make an assertion above that mainnet addresses are 01 and testnet are 00, which is a true geeneralization, but doesn't explain the whole picture. The CDDL helps with understanding at a bit level how an address is made up: https://github.com/input-output-hk/cardano-ledger/blob/master/eras/shelley/test-suite/cddl-files/shelley.cddl#L89-L100

From this, we see an enterprise address (a base address with no delegation credential) is 0110 if it isn't a script. The hex representation of this is 6. So an enterprise address with just the payment key hash is 60dc107d6faf3fccbfae8b7446e3703f30200c7ae2767e607c88608a90 or in bech32: addr_test1vrwpqlt04ulue0aw3d6ydcms8uczqrr6ufm8ucru3psg4yq3c0kvn.

Here's the cardano-address inspect for that address:

cardano-address address inspect <<< 60dc107d6faf3fccbfae8b7446e3703f30200c7ae2767e607c88608a90
{
    "stake_reference": "none",
    "spending_key_hash_bech32": "addr_test1msg86ma08lxtlt5tw3rwxuplxqsqc7hzwelxqlygvz9fqltwcyd",
    "address_style": "Shelley",
    "spending_key_hash": "dc107d6faf3fccbfae8b7446e3703f30200c7ae2767e607c88608a90",
    "network_tag": 0
}

C. Yes

1
  • Thank you for the detailed answer ! So if I don't add the stake key hash it is an enterprise address. This explains why the Nami wallet doesn't recognise 'addr_test1vrw...0kvn' as its own address.
    – Jey
    Dec 22, 2021 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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