Skip to content

Latest commit

 

History

History
559 lines (469 loc) · 11.8 KB

ens.md

File metadata and controls

559 lines (469 loc) · 11.8 KB
description layout
Learn how to use Airstack to universally resolve and reverse resolve ENS, Namestone, and cb.id to other web3 identities (Farcaster 0x address, Solana address).
title description tableOfContents outline pagination
visible
true
visible
true
visible
true
visible
visible
true

🔷 ENS

Airstack provides easy-to-use APIs for enriching ENS applications and for integrating on-chain ENS data and off-chain data from Namestone and cb.id.

Table Of Contents

In this guide you will learn how to use Airstack to:

Pre-requisites

  • An Airstack account
  • Basic knowledge of GraphQL

Get Started

JavaScript/TypeScript/Python

If you are using JavaScript/TypeScript or Python, Install the Airstack SDK:

{% tabs %} {% tab title="npm" %} React

npm install @airstack/airstack-react

Node

npm install @airstack/node

{% endtab %}

{% tab title="yarn" %} React

yarn add @airstack/airstack-react

Node

yarn add @airstack/node

{% endtab %}

{% tab title="pnpm" %} React

pnpm install @airstack/airstack-react

Node

pnpm install @airstack/node

{% endtab %}

{% tab title="pip" %}

pip install airstack

{% endtab %} {% endtabs %}

Then, add the following snippets to your code:

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

import { init, useQuery } from "@airstack/airstack-react";

init("YOUR_AIRSTACK_API_KEY");

const query = `YOUR_QUERY`; // Replace with GraphQL Query

const Component = () => {
  const { data, loading, error } = useQuery(query);

  if (data) {
    return <p>Data: {JSON.stringify(data)}</p>;
  }

  if (loading) {
    return <p>Loading...</p>;
  }

  if (error) {
    return <p>Error: {error.message}</p>;
  }
};

{% endtab %}

{% tab title="Node" %}

import { init, fetchQuery } from "@airstack/node";

init("YOUR_AIRSTACK_API_KEY");

const query = `YOUR_QUERY`; // Replace with GraphQL Query

const { data, error } = await fetchQuery(query);

console.log("data:", data);
console.log("error:", error);

{% endtab %}

{% tab title="Python" %}

import asyncio
from airstack.execute_query import AirstackClient

api_client = AirstackClient(api_key="YOUR_AIRSTACK_API_KEY")

query = """YOUR_QUERY""" # Replace with GraphQL Query

async def main():
    execute_query_client = api_client.create_execute_query_object(
        query=query)

    query_response = await execute_query_client.execute_query()
    print(query_response.data)

asyncio.run(main())

{% endtab %} {% endtabs %}

Other Programming Languages

To access the Airstack APIs in other languages, you can use https://api.airstack.xyz/gql as your GraphQL endpoint.

Get ENS from a given user(s)

You can get all the ENS names and offchain domains (Namestone & cb.id) of a given user, both primary and non-primary names, by providing either 0x addresses, Solana addresses, Farcaster or Lens profile:

Try Demo

{% embed url="https://app.airstack.xyz/query/SkTlH3Lh3I" %} Show me the ENS of 0x4b70d04124c2996de29e0caa050a49822faec6cc, GJQUFnCu7ZJHxtxeaeskjnqyx8QFAN1PsiGuShDMPsqV, lens/@stani, fc_fname:vbuterin {% endembed %}

Code

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

query GetENS {
  Domains(
    input: {
      filter: {
        owner: {
          _in: [
            "0x4b70d04124c2996de29e0caa050a49822faec6cc"
            "GJQUFnCu7ZJHxtxeaeskjnqyx8QFAN1PsiGuShDMPsqV"
            "lens/@stani"
            "fc_fname:vbuterin"
          ]
        }
      }
      blockchain: ethereum
    }
  ) {
    Domain {
      name
      isPrimary
      resolvedAddress
    }
  }
}

{% endtab %}

{% tab title="Response" %}

{
  "data": {
    "Domains": {
      "Domain": [
        {
          "name": "skynft.eth",
          "isPrimary": false,
          "resolvedAddress": ""
        },
        {
          "name": "quantumexchange.eth",
          "isPrimary": false,
          "resolvedAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
        },
        {
          "name": "vitalik.daohall.eth",
          "isPrimary": false,
          "resolvedAddress": ""
        },
        // Other ENS domains
        }
      ]
    }
  }
}

{% endtab %} {% endtabs %}

Get the 0x address, Lens, and Farcaster from a given ENS name(s)

You can get the 0x address, Lens, and Farcaster of ENS names:

Try Demo

{% embed url="https://app.airstack.xyz/query/LAFfZPgdlt" %} show me the 0x address, Lens, Farcaster of vitalik.eth {% endembed %}

Code

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

query GetUserDetailsFromENS {
  Domains(
    input: { filter: { name: { _in: ["vitalik.eth"] } }, blockchain: ethereum }
  ) {
    Domain {
      resolvedAddress
      resolvedAddressDetails {
        socials {
          profileName
          dappName
        }
      }
    }
  }
}

{% endtab %}

{% tab title="Response" %}

{
  "data": {
    "Domains": {
      "Domain": [
        {
          "resolvedAddress": "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
          "resolvedAddressDetails": {
            "socials": [
              {
                "profileName": "vitalik.eth",
                "dappName": "farcaster"
              },
              {
                "profileName": "lens/@vitalik",
                "dappName": "lens"
              }
            ]
          }
        }
      ]
    }
  }
}

{% endtab %} {% endtabs %}

Get the 0x address, Lens, and Farcaster from a given cb.id (Offchain)

You can get the 0x address, Lens, and Farcaster of cb.ids:

Try Demo

{% embed url="https://app.airstack.xyz/query/OLqqmKXrqj" %} Show me the 0x address, Lens, and Farcaster of yosephks.cb.id {% endembed %}

Code

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

query GetCbDotID {
  Domains(
    input: {
      filter: { name: { _in: ["yosephks.cb.id"] } }
      blockchain: ethereum
    }
  ) {
    Domain {
      resolvedAddress
      resolvedAddressDetails {
        socials {
          profileName
          dappName
        }
      }
    }
  }
}

{% endtab %}

{% tab title="Response" %}

{
  "data": {
    "Domains": {
      "Domain": [
        {
          "resolvedAddress": "0xc7486219881c780b676499868716b27095317416",
          "resolvedAddressDetails": {
            "socials": [
              {
                "profileName": "lens/@yosephks",
                "dappName": "lens"
              },
              {
                "profileName": "yosephks.eth",
                "dappName": "farcaster"
              }
            ]
          }
        }
      ]
    }
  }
}

{% endtab %} {% endtabs %}

Get the 0x address, Lens, and Farcaster from a given Namestone Subdomain (Offchain)

You can get the 0x address, Lens, and Farcaster of Namestone subdomains:

Try Demo

{% embed url="https://app.airstack.xyz/query/tYYXAwIXUu" %} Show me the 0x address, Lens, and Farcaster of namestone.testbrand.eth {% endembed %}

Code

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

query GetNamestone {
  Domains(
    input: {
      filter: { name: { _in: ["namestone.testbrand.eth"] } }
      blockchain: ethereum
    }
  ) {
    Domain {
      resolvedAddress
      resolvedAddressDetails {
        socials {
          profileName
          dappName
        }
      }
    }
  }
}

{% endtab %}

{% tab title="Response" %}

{
  "data": {
    "Domains": {
      "Domain": [
        {
          "resolvedAddress": "0x57632ba9a844af0ab7d5cdf98b0056c8d87e3a85",
          "resolvedAddressDetails": {
            "socials": [
              {
                "profileName": "heeroyuy",
                "dappName": "farcaster"
              }
            ]
          }
        }
      ]
    }
  }
}

{% endtab %} {% endtabs %}

Get All The Solana addresses from a given ENS name

You can get the Solana addresses of ENS names by using the Domains API and checking through the registered multichainAddresses field that has symbol equal to SOL:

Try Demo

{% embed url="https://app.airstack.xyz/query/UHJdGOCe1r" %} Show me alexjcomeau.eth's multichain SOL address {% endembed %}

Code

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

query GetUserDetailsFromENS {
  Domains(
    input: {
      filter: { name: { _eq: "alexjcomeau.eth" } }
      blockchain: ethereum
    }
  ) {
    Domain {
      multiChainAddresses {
        address
        symbol
      }
    }
  }
}

{% endtab %}

{% tab title="Response" %}

{
  "data": {
    "Domains": {
      "Domain": [
        {
          "multiChainAddresses": [
            {
              "address": "0xe0235804378c31948E81441f656D826eE5998Bc6",
              "symbol": "ETH"
            },
            {
              // This is the SOL address registered by user in ENS
              "address": "GJQUFnCu7ZJHxtxeaeskjnqyx8QFAN1PsiGuShDMPsqV",
              "symbol": "SOL"
            }
          ]
        }
      ]
    }
  }
}

{% endtab %} {% endtabs %}

Get All The Solana addresses from a given Namestone Subdomain or cb.id (Offchain)

You can get the 0x addresses of offchain domains (Namestone/cb.id) by using the Domains API:

Try Demo

{% embed url="https://app.airstack.xyz/query/E2MMhhm4ql" %} Show me yosephks.cb.id's multichain SOL address {% endembed %}

Code

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

query MyQuery {
  Domains(
    input: { filter: { name: { _eq: "yosephks.cb.id" } }, blockchain: ethereum }
  ) {
    Domain {
      multiChainAddresses {
        address
        symbol
      }
    }
  }
}

{% endtab %}

{% tab title="Response" %}

{
  "data": {
    "Domains": {
      "Domain": [
        {
          "multiChainAddresses": [
            {
              "address": "bc1qetgl5rx3uuhxek7erfc3wh97m3xkshx8pkdpr5",
              "symbol": "BTC"
            },
            {
              "address": "DETcngVSTXVbetWmRo9kdQe7xD9F19uqWk",
              "symbol": "DOGE"
            },
            {
              "address": "0xc7486219881C780B676499868716B27095317416",
              "symbol": "ETH"
            },
            {
              "address": "ltc1qwsqc8y09w59yqvlwy9c4fkqxu5md33vsr2uak6",
              "symbol": "LTC"
            },
            {
              // This is the SOL address connected to yosephks.cb.id (offchain)
              "address": "HyrNmmmce9W3rDdTQcZHyYvhuxPN6AaY3mVJcS9f4AZw",
              "symbol": "SOL"
            }
          ]
        }
      ]
    }
  }
}

{% endtab %} {% endtabs %}

Developer Support

If you have any questions or need help regarding resolving ENS name(s), please join our Airstack's Telegram group.

More Resources