Converting Between Usernames and Addresses

Overview

Initia Usernames are mapped to wallet addresses using a specific domain format (e.g., xxx.init). This section provides guidelines on how to interact with Move modules that manage these usernames. The functionality includes fetching addresses from usernames and vice versa.

Module Address

The usernames module is not part of the standard library and is deployed through a multisig wallet. The current module address for the usernames module is:

  • 0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a

Fetching Address from Username

To retrieve an address from a username, the get_address_from_name view function is used. The function interface is as follows:

#[view]
public fun get_address_from_name(name: String): Option<address>
curl -X POST "[LCD_URI]/initia/move/v1/accounts/[MODULE_ADDR]/modules/usernames/view_functions/get_address_from_name" \
  -H "accept: application/json" \
  -H "Content-Type: application/json" \
  -d "{ \"args\": [ \"[BCS_ENCODED_NAME]\" ]}"
  
# BCS_ENCODED_NAME is the bcs encoded string without .init
  
#{
#  "data": "\"0x...\"",
#  "events": [],
#  "gas_used": "5699"
#}
  

Fetching Username from Address

To retrieve a username from an address, the get_name_from_address view function is utilized:

#[view]
public fun get_name_from_address(addr: address): Option<String>
curl -X POST "[LCD_URI]/initia/move/v1/accounts/[MODULE_ADDR]/modules/usernames/view_functions/get_name_from_address" \
  -H "accept: application/json" \
  -H "Content-Type: application/json" \
  -d "{ \"args\": [ \"[BCS_ENCODED_ADDRESS]\" ]}"
  
#{
#  "data": "\"abc...\"",
#  "events": [],
#  "gas_used": "5699"
#}
  

Conclusion

Overall, the ability to link wallet addresses with human-readable names is invaluable, significantly improving the user experience by replacing cumbersome hexadecimal addresses with easily recognizable names. This functionality is crucial for the adoption and ongoing use of blockchain technology in everyday applications, making it more approachable and practical for a broader audience.

Last updated

Logo

© 2024 Initia Foundation, All rights reserved.