Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.8 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { ensCommon } from '../common/common';

export const listEnsDomains = createAction({
  name: 'listEnsDomains',
  auth: ensCommon.auth,
  displayName: 'List ENS Domains',
  description: 'List the ENS domains for a given address.',
  audience: 'both',
  aiMetadata: { description: 'Look up all Ethereum Name Service (ENS) domains owned by a given Ethereum address by querying the ENS subgraph on The Graph. Use to discover which ENS names an address controls, along with their subdomains, resolver, and metadata. Requires the wallet address; case is normalized automatically. Read-only and idempotent.', idempotent: true },
  props: {
    address: Property.ShortText({
      displayName: 'Address',
      description: 'Address to list ENS domains for',
      required: true,
    }),
  },
  async run(context) {
    const { address } = context.propsValue;

    if (!address) {
      throw new Error('Address is required');
    }

    const query = `
    {
      domains(where: { owner: "${address.toLowerCase()}" }) {
          id
          name
          labelName
          labelhash
          parent {
            id
          }
          subdomains {
            id
            name
          }
          subdomainCount
          resolvedAddress {
            id
          }
          resolver {
            id
            address
          }
          ttl
          isMigrated
          createdAt
        }
    }
    `;

    const res = await ensCommon.apiCall(
      `https://gateway.thegraph.com/api/${context.auth.secret_text}/subgraphs/id/5XqPmWe6gjyrJtFn9cLy237i4cWw2j9HcUJEXsP5qGtH`,
      'POST',
      { query }
    );
    if (res.errors) {
      throw new Error(res.errors[0].message);
    }

    return res.data.domains;
  },
});