# sgnames.js

> JS SDK for Stargaze names

Latest version **0.1.1** (published 2022-12-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install sgnames.js
pnpm add sgnames.js
yarn add sgnames.js
bun add sgnames.js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2022-12-03 |
| First published | 2022-11-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Nikita Rykov |
| Maintainers | miceve |

## Links

- npm: https://www.npmjs.com/package/sgnames.js
- Repository: https://github.com/public-awesome/sgnames.js
- npm.io page: https://npm.io/package/sgnames.js

## Dependencies (3)

- [buffer](https://npm.io/package/buffer.md) ^6.0.3
- [@cosmjs/encoding](https://npm.io/package/@cosmjs/encoding.md) ^0.29.4
- [isomorphic-fetch](https://npm.io/package/isomorphic-fetch.md) ^3.0.0

## Recent versions

- 0.1.1 (latest) — 2022-12-03
- 0.1.0 — 2022-12-03
- 0.0.3 — 2022-11-24
- 0.0.2 — 2022-11-24

## README

# Stargaze Names JS SDK

Simple JavaScript library to query Stargaze Names Service

## Installation 

```sh
yarn add sgnames.js
```

Usage as CJS
```js
const SGNames=require("sgnames.js");
```

Usage as ESM
```js
import SGNames from "sgnames.js";
```

## Usage

### Setting custom network

```js
SGNames.setEndpoint('LCD endpoint of network').setCollectionContract('Contract address of names collection')
```

Possible networks:

- Elgafar testnet
  
  LCD Endpoint: `https://rest.elgafar-1.stargaze-apis.com`

  Names Collection Contract: `stars1rp5ttjvd5g0vlpltrkyvq62tcrdz949gjtpah000ynh4n2laz52qarz2z8`
- Stargaze mainnet
  
  LCD Endpoint: `https://rest.stargaze-apis.com`

  Names Collection Contract: `stars1fx74nkqkw2748av8j7ew7r3xt9cgjqduwn8m0ur5lhe49uhlsasszc5fhr`

### Fetch Name Info

```js
await SGNames.fetchNameInfo("my-awesome-name")
```

Returns object of such structure:

```js
{
    name:"my-awesome-name.stars",
    owner:"stars1...",
    addresses:{
        stars:"stars1...",
        akash:"akash1...",
        osmo:"osmo1...",
        ...
    } (nullable),
    stargazeAddress:"stars..." (nullable),
    imageNFT:{
        collection:"stars1..." (NFT collection contract),
        token_id:"1" (NFT ID)
    },
    records:{
        twitter:"my_twitter_account",
        discord:"example#0000",
        ...
    }
}
```

### Fetch name associated with address

One address can have many names, however only one name can be associated with one address, making bidirectional linking and possibility for reverse lookups.
Here's example how to fetch associated name of specified address:
```js
await SGNames.fetchNameOfAddress("stars1...")
```
Returns same object as fetch name info.

### Fetch owner of name

```js
await SGNames.ownerOf("my-awesome-name")
```
Returns Stargaze address of owner of name, even if name is not associated with it.

### Names of address

Fetch all names of specified address.

```js
await SGNames.namesOf("stars1...")
```

Returns array of all names of address.
```js
["my-awesome-name","more-awesome-name","themostawesomename","helloworld", ...]
```

---
_Source: https://npm.io/package/sgnames.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
