CodeChain Address Formats

JinGyeong Jeong
CodeChain
Published in
5 min readApr 16, 2019

There are two types of addresses in CodeChain. The first type is called a PlatformAddress, which enables users to own CCC and pay for transaction fees. The second type is called an AssetAddress, which enables users to own assets created on CodeChain. CodeChain’s assets follow Bitcoin’s UTXO model, and thus, AssetAddresses’ mechanisms are identical to Bitcoin addresses. In the following, let’s discuss how Bitcoin addresses function.

Bitcoin Address

The key function of the address is to be able to receive money once you send your address to the other party. In the case of Bitcoin, there is no part of the transaction that explicitly allows the user to write his address. Instead, a script is written in the scriptPubKey field of the transaction Output to indirectly display the owner. That is, the address of the Bitcoin is converted into a script.

The 3 types of addresses supported by Bitcoin Core are as follows:

  1. P2PKH which begin with the number 1, eg: 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2.
  2. P2SH type starting with the number 3, eg: 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy.
  3. Bech32 type starting with bc1, eg: bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq.

P2PKH and P2SH are Bitcoin standard scripts. As an example, the scriptPubKey of P2PKH is shown below:

OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG

Except for pubKeyHash mentioned above, the rest are constant values. Since the first “1” in Bitcoin addresses signifies P2PKH, encoding just the pubKeyHash can restore P2PKH’s scriptPubKey completely. Bitcoin address additionally encodes the version and the 4-byte checksum. Versions and checksums prevent BTCs from being sent to the wrong address.

Bech32

Bech32 is a new encoding format for Bitcoin. Bech32 encoding has several advantages over existing address formats. First, it uses Base32 encoding instead of Base58 encoding. It only uses 32 characters from the 26 letters of the alphabet and the 10 digits (it excludes the ones that could be confused for another). In one address, it either uses all upper case letters or all lower case letters, so it is less confusing when you hand-write it, type it on your keyboard, or when you read it aloud. The advantage of using alphanumeric mode when creating QR codes is that the QR codes become simpler.

Bech32 distinguishes between the human-readable part (HRP) and the data part. HRP is not encoded in Base32, but appears as the value itself at the beginning of the address. In Bitcoin, Bech32 is used to distinguish between the mainnet and the testnet. For example, the mainnet address starts with “bc” and the testnet address starts with “tc”.

bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq

Following the HRP, there is a separator “1”, which separates the data and the HRP. Followed by that is value encoded data, and the last 6 characters are the checksum. If the HRP or data changes, the checksum also changes. If you make a mistake while typing an address, you can catch that error during the checksum verification process.

Ethereum Address

Ethereum’s address is relatively simple. The address is the first 160-bit of result of hashing the public key by using the KECCAK256 hash. Ethereum uses both upper and lowercase letters for the checksum method. However, there are a lot of wallets and exchanges that do not check the checksum for user convenience. Instead, it shows a picture like identicon, but this can be ignored because it is intended for human identification. This is not effective in preventing misuse of the addresses.

CodeChain Address Formats

As mentioned earlier, CodeChain has two kinds of addresses: PlatformAddress and AssetAddress. Both addresses use formats where the separator “1” is removed from Bech32.

CodeChain Platform Address

The PlatformAddress is the address used for the Account model. In CodeChain, Account is used for mining, sending and receiving CCC, and sending transactions.

The mainnet address starts with “ccc” and the Corgi testnet address starts with “wcc”. The version and the Account ID are encoded as data parts. The version is a field that is reserved for future addition of functions, and currently only 1 exists. The Account ID is the public key returned by the BLAKE160 hash. There is an advantage in that it can distinguish between mainnet / testnet as compared with Ethereum addresses and can prevent wrong address usage because a checksum exists.

Let’s look at an example of the PlatformAddress.

Example of a PlatformAddress

The above address is divided into “ccc”, “qr5 … yeq “, and” jjd6g0 “. “ccc” is the HRP of Bech32. The first two letters “cc” indicates the network ID, and the third letter “c” means this address is a PlatformAddress. “qr5 … yeq “ is the version encoded with the Account ID. The last six characters of the address “jjd6g0”, are checksums. HRP and checksums are not used after verification. CodeChain internally uses only the Account ID.

CodeChain Asset Address

The AssetAddress is the address used in the UTXO model. They are used to exchange assets generated by CodeChain. Bitcoin shows the owner with the scriptPubKey in the transaction Output, and in CodeChain, the lockScriptHash and the parameters field show the owner in the Output of the AssetTransfer transaction. The standard script in CodeChain always has the same lockScriptHash. The P2PKH of CodeChain is as follows:

The mainnet address of AssetAddress starts with “cca”. For Corgi testnet, it starts with “wca”.

Let’s take a look at an example of AssetAddress.

Like the PlatformAddress, it can be divided into “cca”, “qyq…0es”, “s3h5m2”. The checksum is the same as the PlatformAddress. The first two letters of the HRP should be the network ID and the third letter should be “a”. “qyq … 0es” is the version, type, and payload encoded value. There are currently only 1 version. As for types, there only exist between 0 or 2. Type 1 and type 2 represent P2PKH and P2PKHBurn respectively. In the case of type 1, lockScriptHash is 0x5f5960 … And the payload is the pubKeyHash, which is the first argument to the parameters. Type 0 is the address type used when parameters are empty and only lockScriptHash is specified. In this case, the payload is the lockScriptHash value. It is possible to create an address even if it is not a standard script using a type 0 address.

Conclusion

In CodeChain, PlatformAddress is internally converted to an Account ID, and AssetAddress is internally converted to a lockScriptHash and parameters. Both addresses use Bech32 as a variant. You can distinguish whether it is the mainnet, the testnet, the PlatformAddress or the AssetAddress by checking the first part of the address, and there is a checksum at the end so that any mistakes within any letters in the address can be detected.

--

--