> ## Documentation Index
> Fetch the complete documentation index at: https://docs.initia.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Querying Initia Usernames

## Module Addresses

| Network                | Address                                                                                                                                                                                                 |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Testnet (initiation-2) | [0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a](https://scan.testnet.initia.xyz/initiation-2/modules/0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a/usernames) |

## Tutorials

### Getting Address from Usernames

To retrieve an address from a username, we use the `get_address_from_name`
function. The function interface is as follows:

```move theme={null}
#[view]
public fun get_address_from_name(name: String): Option<address>
```

```js InitiaJS theme={null}
const { RESTClient, bcs } = require('@initia/initia.js')

const moduleAddress = '0x...'
const name = 'initia'
const restClient = new RESTClient('https://rest.testnet.initia.xyz', {
  gasPrices: '0.015uinit',
  gasAdjustment: '1.5',
})

restClient.move
  .view(
    moduleAddress,
    'usernames',
    'get_address_from_name',
    [],
    [bcs.string().serialize(name).toBase64()],
  )
  .then(console.log)

// Response:
// {
//   data: '"0x.."',
//   events: [],
//   gas_used: '5699'
// }
```

### Getting Usernames from Address

To retrieve a username from an address, we use the `get_name_from_address`
function.

```move theme={null}
#[view]
public fun get_name_from_address(addr: address): Option<String>
```

```js InitiaJS theme={null}
const { RESTClient, bcs } = require('@initia/initia.js')

const moduleAddress = '0x...'
const address = 'init1...'
const restClient = new RESTClient('https://rest.testnet.initia.xyz', {
  gasPrices: '0.015uinit',
  gasAdjustment: '1.5',
})

restClient.move
  .view(
    moduleAddress,
    'usernames',
    'get_name_from_address',
    [],
    [bcs.address().serialize(address).toBase64()],
  )
  .then(console.log)

// Response:
// {
//   data: '"abc..."',
//   events: [],
//   gas_used: '5699'
// }
```
