EIP55 and Bech32 address format compatibility scheme
#
JSON RPC interfaceThe jsonrpc interface of PlatON node supports EIP55 (0xxxxx...) address and Bech32 (latxxxxx...) Two kinds of address formats, but the parameters and return values when calling a specific interface can only be selected a certain address format, can not be mixed, the use of different address formats are as follows.
EIP55 address
PlatON is fully compatible with the jsonrpc interface of Ethernet. To use the address in EIP55 format, just follow the way of calling Ethernet jsonrpc. Note the following points.
cannot use the interface prefixed with
platon_
, must be modified to prefixeth_
for interfaces with prefixes other than
platon_
andeth_
, PlatON adds an optional fieldbech32
, which marks whether the Bech32 address needs to be used, with the default value of EIP55, note that if you want to use the EIP55 format, you cannot take the bech32 fieldcurl -X POST --data '{"jsonrpc":"2.0", "method": "txpool_contents", "params": [], "id": 1}'
The return value is
{"jsonrpc":"2.0","id":1,"result":["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]}
The address fields in both the input and return values are in EIP55 format
Bech32 address
To use Bech32 addresses, note the following.
you cannot use an interface prefixed with
eth_
, you must modify it to be prefixed withplaton_
for interfaces with prefixes other than
platon_
andeth_
, PlatON adds an optional fieldbech32
which marks whether or not a Bech32 address needs to be used, the default value is EIP55, note that if you want to use the Bench32 format, you must bring thebech32
field and set it totrue
curl -X POST --data '{"jsonrpc":"2.0","bech32":true, "method": "txpool_contents", "params": [], "id": 1}'
The return value is
{"jsonrpc":"2.0","id":1,"result":["lat1zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqp7pn3ep"]}
the address fields in both the input and return values are in Bench32 format
#
SDKPlatON can be called using the Ethernet SDK and the PlatON SDK, noting the following points.
- you can only use the EIP55 address with the Ethernet SDK, not the Bech32 address
- Using PlatON SDK can only use Bech32 address at the moment, not EIP55 address
#
How DAPP is compatible with EIP55 and Bech32DAPP can achieve business support for both EIP55 and Bech32 addresses through address translation as follows.
Use jsonrpc interface
If the DAPP calls the jsonrpc interface directly, it can choose any of the following methods.
- convert the Bech32 address to EIP55 address and call the EIP55 address according to the call method introduced earlier
- convert the EIP55 address to Bech32 address, and call the Bech32 address according to the call method described above
Using SDK
If the DAPP uses the SDK to call PlatON, it can choose any of the following methods.
- Convert the Bech32 address to an EIP55 address and call it using the Ethernet SDK
- Convert EIP55 address to Bech32 address and call with PlatON SDK
#
Address conversion methodThe interconversion between Bech32 addresses and EIP55 addresses is provided in PlatON's SDK, which supports three development languages.
from platon_utils import to_bech32_address, to_checksum_addressto_bech32_address('0x0000000000000000000000000000000000000001', 'lat')to_checksum_address('lat1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpfr7f80')
Bech32.addressEncode("lat","0x676c0d9b7da640a25dabd5788612f5faa16cc6b9"));Bech32.addressDecodeHex("lat1vakqmxma5eq2yhdt64ugvyh4l2ske34eay86pg"));
web3.utils.decodeBech32Address('lat', 'lat1zg69v7yszg69v7yszg69v7yszg69v7y30mluqx');web3.utils.toBech32Address('lat', '0x1234567890123456789012345678901234567891');