Somnia Domain Services
  • What is Somnia Domain Services (SDS)?
  • For Developers
    • How It Works?
    • Quick Start (SDK)
    • Example Website Integration
    • Example RainbowKit Integration
Powered by GitBook
On this page
  • 📁 1. Copy the SDK file
  • 💻 2. Usage
  • 🔄 Use Case
  1. For Developers

Quick Start (SDK)

The Somnia SDK lets you resolve .som names using just one function. It works anywhere you can use TypeScript or JavaScript.


📁 1. Copy the SDK file

Add this file to your project:

lib/sds.ts

sds.ts content:

import { ethers } from "ethers";

const RPC_URL = "https://dream-rpc.somnia.network";
const CONTRACT_ADDRESS = "0xDB4e0A5E7b0d03aA41cBB7940c5e9Bab06cc7157";
const CONTRACT_ABI = [
  {
    inputs: [{ internalType: "address", name: "owner", type: "address" }],
    name: "reverseLookup",
    outputs: [{ internalType: "string", name: "", type: "string" }],
    stateMutability: "view",
    type: "function"
  }
];

const provider = new ethers.JsonRpcProvider(RPC_URL);
const contract = new ethers.Contract(CONTRACT_ADDRESS, CONTRACT_ABI, provider);

export async function getPrimarySomName(walletAddress: string): Promise<string | null> {
  try {
    const name = await contract.reverseLookup(walletAddress);
    return name;
  } catch (err) {
    console.error("Somnia name lookup failed:", err);
    return null;
  }
}

💻 2. Usage

Anywhere in your app:

import { getPrimarySomName } from "./lib/sds";

const somniaName = await getPrimarySomName("0x1234...abcd"); // Or the string wallet address variable of the wallet API you are using 
console.log(somniaName); // "test.som" or null

🔄 Use Case

Display .som names instead of addresses:

const label = somniaName || walletAddress;
PreviousHow It Works?NextExample Website Integration

Last updated 7 days ago