> For the complete documentation index, see [llms.txt](https://painor.gitbook.io/gramjs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://painor.gitbook.io/gramjs/working-with-usernames/contacts.resolveusername.md).

# contacts.resolveUsername

Resolve a @username to get peer info

## Example

{% tabs %}
{% tab title="Javascript" %}

```javascript
const {Api, TelegramClient} = require('telegram');
const {StringSession} = require('telegram/sessions');

const session = new StringSession('');
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
    const result = await client.invoke(new Api.contacts.resolveUsername({
        username: 'random string here',
        }));
    console.log(result); // prints the result
})();
```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
import {Api, TelegramClient} from 'telegram';
import {StringSession} from 'telegram/sessions';

const session = new StringSession('');
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
    const result: Api.contacts.ResolvedPeer = await client.invoke(new Api.contacts.resolveUsername({
        username: 'random string here',
        }));
    console.log(result); // prints the result
})();
```

{% endtab %}
{% endtabs %}

## TL schema

```
contacts.resolvedPeer#7f077ad9 peer:Peer chats:Vector<Chat> users:Vector<User> = contacts.ResolvedPeer;
---functions---
contacts.resolveUsername#f93ccba3 username:string = contacts.ResolvedPeer;
```

## Parameters

|     Name     | Type                                            | Description          |
| :----------: | ----------------------------------------------- | -------------------- |
| **username** | [string](https://core.telegram.org/type/string) | @username to resolve |

## Result

[contacts.ResolvedPeer](https://core.telegram.org/type/contacts.ResolvedPeer)

## Possible errors

| Code | Type                             | Description                                                                           |
| :--: | -------------------------------- | ------------------------------------------------------------------------------------- |
|  401 | AUTH\_KEY\_PERM\_EMPTY           | The temporary auth key must be binded to the permanent auth key to use these methods. |
|  400 | CONNECTION\_DEVICE\_MODEL\_EMPTY | Device model empty                                                                    |
|  400 | CONNECTION\_LAYER\_INVALID       | Layer invalid                                                                         |
|  400 | USERNAME\_INVALID                | The provided username is not valid                                                    |
|  400 | USERNAME\_NOT\_OCCUPIED          | The provided username is not occupied                                                 |

## Can bots use this methd ?

### yes

## Related pages
