The relationship between ex and 0x addresses, and how to convert them to each other
The relationship between ex and 0x address
There are two address formats in exchain, one is the address at the ex prefix, for example: ex1ya7dn2rr8nx07tx9ksq8gvz5utvarrh0knjnjn
; the other address starts with 0x, for example: 0x8AF3B04B0400B16911B512360122148056D562
. Address prefixes with 0x and ex come from the same mnemonic, they have the same balance under their addresses, and the owners of both addresses have the same amount of okt. After importing the mnemonic into the metamask, addresses starting with 0x can be recovered; use okexchaincli to view addresses starting with 0x and ex. You can use exchain on the dex web page and mobile client to view address prefixes.
how to use
Addresses starting with ex can be directly used for operations on mobile clients, webpages or on okexchainCl, such as transfer, deposit and voting addresses starting from 0x, which can only be used for transfer operations on Metamask at present.
Note
: Using the address prefix of ex can only transfer funds to the address prefix of ex, and cannot cross-transfer.
Mutual conversion
The address prefixed with 0x and the address prefixed with ex come from the same mnemonic, which can be converted into each mnemonic. Other addresses start with 0x in hexadecimal format. Ethereum currently uses the following address format. The address prefix is 0x, and the format is standardized. From the btc protocol BIP173 (bech32), currently btc and cosmos use this format address.
The addresses of the two formats can be converted to each other. Conversion method: use [okexchain java sdk](https://github.com/okx/okexchain-java-sdk/blob/release/v0.16.4/src/main/java/com /okexchain/utils/crypto/AddressUtil.java)okexchain javascript sdk method convert address from convertAddressFromHexToBech32 and convertAddressFromBech32ToHex to convert the address
Convert the old version of okexchain prefix address to the new version of ex prefix address
####javascript-sdk
crypto.convertOKExChainAddressToExAddress("okexchain1vlzgq74y6hm9crhkkhdjy77uvyqa0zdusu258y")
In jssdk, there is a method for switching between addresses starting with ex and addresses starting with 0x. Call method:
Ex address is converted to 0x address
crypto.convertBech32ToHex(okexchain address)
For example: let hexAddress = crypto.convertBech32ToHex("ex1ya7dn2rr8nx07tx9ksq8gvz5utvarrh0knjnjn")
Convert 0x address to ex address
crypto.convertHexToBech32(0x address);
For example: let bech32Address = crypto.convertHexToBech32("0x277CD9a8633ccCFF2Cc5B400743054e2d9d18eEf")
Implementation details:
https://github.com/okx/okexchain-javascript-sdk/blob/master/src/crypto/index.js
Java-SDK
- Link
- You can use the methods convertFromOkexchainBech32ToExBech32 and convertFromOkexchainValToExVal to convert between okexchain addresses and ex addresses
- Reference example
string hexAddr = convertAddressFromBech32ToHex("okexchain1vlzgq74y6hm9crhkkhdjy77uvyqa0zdusu258y
");
convertAddressFromHexToBech32("ex", hexAddr);
go-sdk
- Link
- The okexchain address and ex address can be converted through the method AccAddrPrefixConvert
- Validator address conversion through ValAddrPrefixConvert
- Reference example
AccAddrPrefixConvert("okexchain", "okexchain1vlzgq74y6hm9crhkkhdjy77uvyqa0zdusu258y
", "ex")
ValAddrPrefixConvert("okexchainvaloper", "okexchainvaloper1vlzgq74y6hm9crhkkhdjy77uvyqa0zdu3c6tmx", "exvaloper")