DARWINIA NETWORK
Published in

DARWINIA NETWORK

「Build on Darwinia 2–1」Address Formats in Darwinia

This article will introduce address formats we use in Darwinia, Crab and other testnets, and the relationship between them.

Introduction

You will find different address formats(account formats) in the blockchain domain, which can sometimes be confusing for non-experts. For those who want a quick answer on which format to use in different scenarios, skip to the section — When to Use Which.

Below the surface, addresses are nothing more than long binary numbers. However, non-printing characters are clumsy to copy, paste and share, so addresses always come in printing characters.

Why are there so many address formats?

Below the surface, addresses are nothing more than sequences of binary bits. However, non-printing characters are clumsy to copy, paste and share, so addresses always come in printing characters. Different address formats coexist for the following reasons.

First, in the blockchain industry, there is no central institution to manage and distribute accounts. Theoretically, accounts from two different blockchains may have identical addresses, although there is no connection between the two. Therefore, it can be a good thing that different blockchains adopt different formats. Suppose a user has USDTs in two different blockchains. If the two blockchains adopt different address formats, the chance of confusing them is lower. We know that transferring assets to the wrong address may cause irrecoverable losses, and different formats for different blockchains can at least partly mitigate such issues.

Secondly, addresses of the same format can use prefixes to distinguish different networks. For example, Substrate-based blockchains such as Polkadot and Darwinia adopt the address format of SS58. Apart from a generic Substrate address(starting with the number 5), an account can have different addresses in different networks. We will explain it in detail in the section — More on Substrate Addresses.

In addition, compatibility can also be a concern. Darwinia(with its testnets) is a Substrate-based blockchain and a participant of the Polkadot ecosystem. We also support smart contracts and dApps developed for Ethereum, and developers can port their smart contracts or dApps to our networks with the least modification. Therefore, every account has an Ethereum format address, a 42-character hexadecimal address that starts with 0x, which we call a DVM address.

We will explain the relationship between a DVM address and a Substrate address with an example.

Address Formats by an Example

Address Generation

Let’s create/restore an account from a 12-word mnemonic seed in MetaMask. Here we use

dutch walnut battle make gorilla tomorrow oblige earth current muscle auto cry

NOTE: The address used here is only for educational purposes, and DO NOT transfer or deposit any assets to it.

After some setting, you will get the Ethereum address.

0x5ED61E64AA17f2B7726FEfB267676DDc14E24B57

Now, if you connect to other Ethereum-compatible networks, the address will not change. We can try to connect to Crab, which is Ethereum-compatible, and you will see the address is the same, and that is what we call a DVM address.

Address Conversion

But in our Apps Portal, when a user tries to transfer assets(CRAB/CKTON) to another address in the Crab network, the receiving address should be in the Substrate format. Users can use the online converter to convert a DVM address to a Substrate one.

5ELRpquT7C3mWtjepyjZgHHxwJVzRHEGXiyXd5HXanHmTVSp

This address points to the same account in Crab as the DVM address. Assets transferred to this address can be seen in the DVM address with MetaMask.

More on Substrate Addresses

More complicated still, the Substrate format contains an address type prefix that identifies an address as belonging to a specific network. The address we have generated is a generic Substrate address, which starts with the number 5.

You can use the Subscan tool to convert this generic address into addresses used in other Substrate-based blockchains.

We can see that the Darwinia address starts with the number 2 and the Crab address is the same as the generic address.

It is important to understand that different network formats are merely other representations of the same public key in a private-public keypair generated by an address generation tool. In other words, as long as you have the private key or the 12-word mnemonic seed, you have access to all these addresses.

When to Use Which

For Apps Portal users

  • If you are connected to Darwinia Network and want to transfer RING/KTON from an account to another, make sure to use the Substrate address for Darwinia, which starts with the number 2, for the ‘send to address’ input box.
  • If you are connected to Crab Network and want to transfer CRAB/CKTON from an account to another, make sure to use the Substrate address for Crab, which starts with the number 5, for the ‘send to address’ input box.

For Smart App users

  • If you want to transfer assets(CRAB/CKTON) from a Crab Smart address to a Substrate address for Crab, you connect to the Smart Module in the Crab Network with MetaMask and fill the receiving account’s Substrate address for Crab, which starts with the number 5, in the ‘Destination address input box.
  • If you want to transfer assets(CRAB/CKTON) from a Substrate address for Crab to a Crab Smart address, you connect to the Crab Network with polkadot{.js} and fill the receiving account’s DVM address, which starts with 0x, in the Destination address input box.

For Wormhole users

  • If you want to transfer assets(RING/KTON) from Ethereum to Darwinia, the Recipient part should be a Substrate address for Darwinia, which starts with the number 2.
  • If you want to transfer assets(RING/KTON) from Darwinia to Ethereum, the Recipient part should be a real Ethereum address, which starts with 0x.

Others

Some third-party developers have ported their smart contracts or dApps from Ethereum to Crab Network. Users interact with these third-party smart contracts or dApps with MetaMask or other Ethereum-compatible wallet, so DVM addresses are used in most cases.

Appendix

For those who are interested in the details of the address conversion, we will use the same example to explain how an EVM address is converted to a Substrate address used in Darwinia Network with the following diagram step by step.

(We express the byte arrays in hexadecimal for convenience.)

  • DVM Address (20 bytes)

Let’s start with the Ethereum-compatible address(DVM Address) used in the previous example.

0x5ED61E64AA17f2B7726FEfB267676DDc14E24B57

  • AccountID Prefix (11 bytes)

We add a fixed prefix before the DVM address. The prefix consists of “dvm:” and 7 bytes of zero-padding. Then we have 31 bytes.

0x64766D3A000000000000005ED61E64AA17f2B7726FEfB267676DDc14E24B57

  • CheckSum-1 (1 byte)

Then a simple checksum, which is the result of byte-wise xor operation of the 31 bytes, is appended at the end. Here, the checksum-1 is 0x54. Then we have 32 bytes.

0x64766D3A000000000000005ED61E64AA17f2B7726FEfB267676DDc14E24B5754

This sequence of 32 bytes is a normal SubKey public key which is used for storage and transfer in Substrate-based blockchains. It can also be referred to as an AccountID.

  • Address Type Prefix (1 bytes)

The address type prefix identifies which network the address is used. For Darwinia, it is 18 or 0x12. Prepend it to the AccountID and we have 33 bytes.

0x1264766D3A000000000000005ED61E64AA17f2B7726FEfB267676DDc14E24B5754

  • Checksum-2 (2 bytes)

Then 2 bytes of checksum is to appended at the end. The steps of calculating the checksum are as follows:

  1. Concatenate the string ‘SS58PRE’(0x53533538505245) and the previous 33 bytes to get a temporary byte array of length 40. (The string ‘SS58PRE’ will not be included in the final address.)

0x535335385052451264766D3A000000000000005ED61E64AA17f2B7726FEfB267676DDc14E24B5754

2. Use the hash function Blake2–512 on this byte array to get a digest of 64 bytes(512bits), and the first two bytes, 0xE2AA, are the checksum. Append the checksum to the 33 bytes, and we have a byte array of length 35.

0x1264766D3A000000000000005ED61E64AA17f2B7726FEfB267676DDc14E24B5754E2AA

  • Base58Check Encoding

The final step is to encode the byte array with Base58Check encoding, and the Substrate address used in Darwinia network is:

2qSbd2umtD4KmV2X6CczceumRf4w6t7n19gNrfrJUG24hsnZ

About Darwinia Network

Darwinia Network is a decentralized cross-chain bridge network building on Substrate, which is the “cross-chain bridge hub” of the Web 3.0 Metaverse. It provides a safe and general bridging solution, connects to Polkadot, Ethereum, TRON, and other heterogeneous chains by cross-chain transfer of assets and remote chain calls.

Darwinia Network has gained high reputation and recognition along the way to build the decentralized cross-chain bridge protocol. In 2020, Darwinia was written in Polkadot light-paper as one of the friends of Polkadot and Substrate. And Darwinia was selected to join Substrate Builder Program and Web3.0 Bootcamp, and for the outstanding work in Substrate Builder Program, Darwinia Network was officially awarded the Level 2 badge by Parity. The products and tools developed by Darwinia have been rewarded three W3F Grants.

Darwinia has been contributing to the compatibility and interoperability of the Metaverse.

The application areas of Darwinia Network include DeFi, cross-chain NFT trading, games, etc. Darwinia also develops the Metaverse game Evolution Land.

GithubWebsite | Twitter | Telegram | Medium

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Darwinia

Darwinia

As an open cross-chain bridge protocol based on Substrate, Darwinia focuses on the construction of future Internet of Tokens. TG: http://t.me/DarwiniaNetwork