Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 160 additions & 58 deletions developers/developer-guides/integrating-initia-apps/usernames.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Querying Initia Usernames
title: Integrating Initia Usernames
---

## Module Addresses
Expand All @@ -10,77 +10,179 @@ title: Querying Initia Usernames

## Tutorials

### Getting Address from Usernames
### Registering a Username

To retrieve an address from a username, the `get_address_from_name` view function is used. The function interface is as follows:
To register and set a username, the `register_domain` and `set_name` functions are used. The function interfaces are as follows:

```move
#[view]
public fun get_address_from_name(name: String): Option<address>
public entry fun register_domain(account: &signer, domain_name: String, duration: u64)
public entry fun set_name(account: &signer, domain_name: String)
```

```js InitiaJS
const { LCDClient, bcs } = require('@initia/initia.js');

const moduleAddress = '0x...';
const lcdUri = 'https://...';
const name = 'initia';
const lcd = new LCDClient(lcdUri);

lcd.move
.view(
moduleAddress,
'usernames',
'get_address_from_name',
[],
[bcs.string().serialize(name).toBase64()]
The following example demonstrates how to register and set a username using InitiaJS:

```ts InitiaJS
import { bcs, LCDClient, MnemonicKey, MsgExecute, Wallet } from '@initia/initia.js';

async function main() {
const moduleAddress = '0x...';
const lcdUri = 'https://...';

const domainName = 'initia';
const duration = 31557600; // 1 year

const lcd = new LCDClient('https://lcd.ininiation-1.initia.xyz', {
gasAdjustment: '1.75',
gasPrices: '0.15uinit'
})

const wallet = new Wallet(
lcd,
new MnemonicKey({
mnemonic: 'power elder gather acoustic valid ... '
})
)
.then(console.log);

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

const msgs = [
new MsgExecute(
wallet.key.accAddress,
moduleAddress,
'usernames',
'register_domain',
[],
[
bcs.string().serialize(domainName).toBase64(),
bcs.u64().serialize(duration).toBase64(),
]
),
new MsgExecute(
wallet.key.accAddress,
moduleAddress,
'usernames',
'set_name',
[],
[
bcs.string().serialize(domainName).toBase64(),
]
)
]

const signedTx = await wallet.createAndSignTx({ msgs })
await wallet.lcd.tx.broadcastSync(signedTx).then(res => console.log(res));
}
```

### Getting Usernames from Address
### Getting Address and Usersnames

To retrieve a username from an address, the `get_name_from_address` view function is utilized:
To retrieve an address from a username, the `get_address_from_name` and `get_name_from_address` view function is used. The function interfaces are as follows:

```move
#[view]
public fun get_address_from_name(name: String): Option<address>

#[view]
public fun get_name_from_address(addr: address): Option<String>
```

```js InitiaJS
const { LCDClient, bcs } = require('@initia/initia.js');

const moduleAddress = '0x...';
const lcdUri = 'https://...';
const address = "init1...";
const lcd = new LCDClient(lcdUri);

lcd.move
.view(
moduleAddress
'usernames',
'get_name_from_address',
[],
[
bcs
.address()
.serialize(address)
.toBase64(),
]
The following example demonstrates how to retrieve an address from a username using InitiaJS:

```ts InitiaJS
import { bcs, LCDClient } from '@initia/initia.js';

async function main() {
const moduleAddress = '0x...';
const lcdUri = 'https://...';
const name = 'initia';
const lcd = new LCDClient(lcdUri);

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

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

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

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

### Extening expiration dates

To extend the expiration date of a domain, the `extend_expiration` function is used. The function interface is as follows:

```move
public entry fun extend_expiration(account: &signer, domain_name: String, duration: u64)
```

The following example demonstrates how to extend the expiration date of a domain using InitiaJS:

```ts InitiaJS
import { bcs, LCDClient, MnemonicKey, MsgExecute, Wallet } from '@initia/initia.js';

async function main() {
const moduleAddress = '0x...';
const lcdUri = 'https://...';

const domainName = 'initia';
const duration = 31557600; // 1 year

const lcd = new LCDClient('https://lcd.ininiation-1.initia.xyz', {
gasAdjustment: '1.75',
gasPrices: '0.15uinit'
})

const wallet = new Wallet(
lcd,
new MnemonicKey({
mnemonic: 'power elder gather acoustic valid ... '
})
)
.then(console.log);

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

const msgs = [
new MsgExecute(
wallet.key.accAddress,
moduleAddress,
'usernames',
'extend_expiration',
[],
[
bcs.string().serialize(domainName).toBase64(),
bcs.u64().serialize(duration).toBase64(),
]
)
]

const signedTx = await wallet.createAndSignTx({ msgs })
await wallet.lcd.tx.broadcastSync(signedTx).then(res => console.log(res));
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: VIP Scoring Tutorial
---

Comming soon.
Loading