# Smart Contract

**Integration with Github**

> Ether NS (Ethereum Mainnet) : <https://github.com/ethernameservice/EtherNS>
>
> ERA NS (zkSync ERA) : <https://github.com/ERA-name-service/Era-Name-Service-for-zkSync-Era-Mainnet>
>
> Polygon NS (Polygon zkEVM) : <https://github.com/Polygon-NS/Polygon-Name-Service>
>
> Linea NS (Linea Mainnet) : <https://github.com/Linea-Name-Service/Linea-Name-Service>
>
> Scroll NS (Scroll Mainnet) : <https://github.com/Scroll-Name-Service/Scroll-Name-Service>
>
> Manta NS (Manta Pacific) : [https://github.com/Manta-Domain/Manta-Name-Service](https://github.com/manta-domain/manta-name-service)
>
> .zr NS (Zora Mainnet)  : <https://github.com/zora-name-service/Zora-Name-Service/>
>
> .bns NS (Base) : <https://github.com/basenameservice/Base-Name-Service/>

[**Ether Name Service integration**](#user-content-fn-1)[^1]

This document will help you incorporate ether name services into your projects. In the document, available functions are examined by including web3.js and Ether name service in your project.

{% hint style="info" %}
To use our library, replace the line in the 5th row of index.js with the contract address on the blockchain you want to use. By default, it uses the Ether contract on the mainnet.&#x20;

To view contract addresses, visit the "[Verified Smart Contracts](https://docs.ether.domains/ns/developers/verified-smart-contracts)" page.

````javascript
// Some code
```javascript
const c_address = "0x6bfdc5b9529355409b13ed7d0b2df14a8e45b516"; //mainnet
```
````

{% endhint %}

{% content-ref url="verified-smart-contracts" %}
[verified-smart-contracts](https://docs.ether.domains/ns/developers/verified-smart-contracts)
{% endcontent-ref %}

#### Requirements

> If you are not actively using it in your project, you should install web3.js.

**NODE**

```
npm install web3
```

**YARN**

```
yarn add web3
```

**In the Browser**

```html
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
```

or

```html
<script src="https://unpkg.com/web3@latest/dist/web3.min.js"></script>
```

#### Installation

**NODE**

```javascript
npm install ethernameservice
```

**In the Browser**

```html
<script src="https://unpkg.com/ethernameservice@1.0.2/index.js"></script>
```

#### Usage

First, we connect with the libraries.

```javascript
const web3 = new Web3(Web3.givenProvider)
// First create a web3js provider

const etherNS = new EtherNS(web3)
// You are now ready for .ether
```

**Primary Address**

Returns the primary address registered to this address.

```javascript
etherNS.primaryAddress("ETH_ADDRESS")
.then(function(result){
    console.log(result)
    // Returns the primary address registered to this address.
})
```

**Resolve Address**

Returns the resolved ethereum address of the name.

```javascript
etherNS.resolveAddress("alice.ether").then(function(result){
    console.log(result)
    // Returns the resolved ethereum address of the .ether name.
})
```

**Address Owners**

Returns the domains owned by an address.

```javascript
etherNS.addressOwners("ETH_ADDRESS").then(function(resultOwners){
	console.log(resultOwners)	
})
```

**Subdomain Status**

This query returns whether the subdomain sale is active.

```javascript
etherNS.subdomainPublicSale("ether_name").then(function(result) {
    if (result) {
        //Subdomain can be registered.
    } else {
        //Subdomain can't be registered.
    }
})
```

**Subdomain Cost**

This query returns the cost of subdomain sales.

```javascript
etherNS.subdomainPublicSale("ether_name").then(function(result_cost) {
    console.log(result_cost)
})    
```

**Last registered names**

Returns the last registered .ether names

```javascript
etherNS.lastAddresses(10).then(function(result){
    console.log(result)
    //Returns the last 10 registered .ether name
})
```

**Is this domain name taken ?**

Returns whether a domain name has been registered by another user.

```javascript
etherNS.isTaken("ether_name").then(function(resultTaken){
    if (resultTaken>0) {
        //This domain name has been registered.
    } 
})
```

**Get Data**

Get domain name information.

```javascript
etherNS.getData("ether_name","data_name").then(function(result){ {
    console.log(result)
});
```

**Get Twitter Account**

Get Twitter account.

```javascript
etherNS.getTwitter(ether_name).then(function(account_twitter){
     console.log(account_twitter)
})
```

**Get Instagram Account**

Get Instagram account.

```javascript
etherNS.getInstragram(ether_name).then(function(account_instagram){
     console.log(account_instagram)
})
```

**Get Discord Account**

Get Discord account.

```javascript
etherNS.getDiscord(ether_name).then(function(account_discord){
     console.log(account_discord)
})
```

**Get Tiktok Account**

Get Tiktok account from.

```javascript
etherNS.getTiktok(ether_name).then(function(account_tiktok){
     console.log(account_tiktok)
})
```

**Get Reddit Account**

Get Reddit account.

```javascript
etherNS.getReddit(ether_name).then(function(account_reddit){
     console.log(account_reddit)
})
```

**Get Telegram Account**

Get Telegram account.

```javascript
etherNS.getTelegram(ether_name).then(function(account_telegram){
     console.log(account_telegram)
})
```

**Get URL**

Get URL.

```javascript
etherNS.getUrl(ether_name).then(function(account_url){
     console.log(account_url)
})
```

**Get Email**

Get Email.

```javascript
etherNS.getEmail(ether_name).then(function(account_email){
     console.log(account_email)
})
```

**Get Description**

Get Description.

```javascript
etherNS.getDescription(ether_name).then(function(account_description){
     console.log(account_description)
})
```

**Get Notice**

Get Notice.

```javascript
etherNS.getNotice(ether_name).then(function(account_notice){
     console.log(account_notice)
})
```

**Get Keywords**

Get Keywords.

```javascript
etherNS.getKeywords(ether_name).then(function(account_keywords){
     console.log(account_keywords)
})
```

**Set New Primary Address**

Changes the primary address.

```javascript
etherNS.setPrimaryAddress("ether_name.ether","OWNER_ETH_ADDRESS").then(function(result){
    if (result['status']) {
     //Successful
     } else {
     //Failed
     }
})
```

**Set New Resolve Address**

Changes the resolve address.

```javascript
 etherNS.setResolveAddress("ether_domain.ether","NEW_RESOLVE_ETH_ADDRESS", "OWNER_ETH_ADDRESS").then(function(result){
        if (result['status']) {
        //Successful
        } else {
        //Failed
        }
 })
```

**Register Main Domain**

Registers a new .ether address and returns the result.

```javascript
etherNS.register("new_domain.ether",YOUR_ETH_ADDRESS,YOUR_REFERRAL_ADDRESS,web3.utils.toWei('0.04', 'ether')).then(function(result){
    if (result['status']) {
        // Registration Successful
    } else {
        // Registration Failed
    }
})
```

**Register Subdomain** (for .ether)

Registers a subdomain address and returns the result.

```javascript
 etherNS.registerSubdomain("MAIN_DOMAIN_NAME","YOUR_ETH_ADDRESS","NEW_SUBDOMAIN_NAME","COST_WEI").then(function(result){
    if (result['status']) {
        // Registration Successful
    } else {
        // Registration Failed
    }    
})
```

**Start or Close subdomain sale** (for .ether)

```javascript
etherNS.setSubdomainSaleActive("true",web3.utils.toWei("0.05",'ether'),"ether_name","OWNER_ETH_ADDRESS").then(function(result){
	if (result['status']) {
     //Successful
     } else {
     //Failed
     }
})
```

**Set Data**

It allows you to add data for the domain name you have.

```javascript
etherNS.setData("ether_name","data_name","data_value", "Owner_Eth_Address").then(function(result){
    if (result['status']) {
     //Successful
     //eq: data_name: twitter, data_value: twitter_account
     } else {
     //Failed
     }
})j
```

[^1]:
