Addressing on Radix
In previous version of Scrypto, addresses used to be represented as hex encoded strings. In general, hex encoded addresses have two key issues:
They are not checksummed, therefore, mistakes in the address can neither be corrected nor detected statically. Without having a checksum, verifying the correctness of an address would require a service which has access to a node and is able to provide information on whether anything exists at the provided address or not.
Without having a human readable part, it is difficult to determine what an address is used for just by looking at it. Even when an entity byte is present in an address, it still requires interpretation. As an example, a hex string could be a package address or a resource address. There is no way to tell what the type of addressed entity is without using an external service.
Scrypto addresses have moved away from being hex encoded and are now Bech32m encoded, where they are made up of a Human Readable Part (HRP), separator, and a base32m encoded data part which includes a 6 character checksum of the HRP and data.
The human readable part is made up of two specifiers that are separated by an underscore ("_"). These are:
Entity Specifier: Specifies the type of entity that this address is for. As an example, in the case of the address being used to address an account component, the entity specifier would be "account". This makes it clear at first glance what the address is meant to be used for.
Network Specifier: Specifies the network that the address is used for. This helps distinguish mainnet address from stokenet address, and so on; making it clear what network the address is use for.
The introduction of Bech32m address encoding to Scrypto comes with a number of benefits:
All addresses are now checksummed and therefore typological errors can be detected and corrected.
The entity specifier makes it clear what the address is meant to represent.
The data encoded in the Bech32m address is the byte representation of the address, which is an array of 30 bytes that is made up of two main parts:
Entity Byte: This is the first byte in the address and it defines the type of entity being addressed.
Address Bytes: These are the remaining 29 bytes in the array and they are the address of the entity.
The supported entity types and their entity byte representation are given in entity_type.rs.
The byte-representation of addresses is lower-level concept and is not something that you will need to use on day-to-day basis.
Entity specifiers are the first part of the Bech32m HRPs used in Scrypto, they are used to specify the type of entity being addressed in a human readable way.
resource_. Any entity specifier starting with
internal_ is of a non-global "internal" entity, and can’t be interacted with directly, aside from very specific instances, such as vault recalls/freezes.
A full list of entity specifiers are given in hrpset.rs.