I spent last week trying to understand how .night domains actually work. Not from a spec sheet, but by building something that touches the chain directly. The result is a small profile viewer. You type in a name like tomin.night, and it resolves the profile straight from the blockchain. No registrar API. No auth wall. Just a smart contract and some JavaScript.

What follows is how it works, what I learned, and the two specific traps that ate my afternoon.

Why On-Chain Names Matter

On Midnight, .night domains are managed by Midnames. Instead of querying a company’s central server, you read directly from a smart contract that lives on the chain. The registry itself holds the domain, the owner, and whatever profile fields the owner attached. Because that data is on-chain, the identity is portable. You are not renting it from a platform that can change terms or pull the plug. If you control the keys, you control the name.

That shift matters for developers too. When you build against a traditional DNS system, you deal with rate limits, API keys, and uptime promises. Here, the contract state is the source of truth. Your application reads it the same way every other application reads it. There is no privileged API tier.

The Code Is Almost Too Simple

The @midnames/sdk handles the heavy lifting. Resolving a domain to an address and profile takes exactly two lines:

const provider = createDefaultProvider({ networkId: "mainnet" });
const result = await resolveDomain(provider, "tomin.night");

That is it. The provider targets the network, and the resolver talks to the contract. The SDK returns a result object that includes a success flag. If the domain does not exist, you do not need layers of error handling or try-catch blocks around RPC failures. The SDK tells you cleanly that nothing is there. This makes building UIs surprisingly pleasant. You can branch on the success flag and show a “not found” state without guessing whether the failure was a missing name or a dead node.

What You Get Back

When the lookup succeeds, the payload contains two pieces that matter.

Target is the wallet address the domain points to. This is the core utility. It turns a long hex address into something a human can read, type, and remember.

Fields hold the profile details. Whatever the owner attached to the domain—social links, avatars, text records—lives inside this structure. These fields are not stored on some company’s MongoDB cluster. They are fields in the contract state, which means any app that knows how to read the registry can render the same profile. No database sync required.

Two Traps That Slowed Me Down

Not everything about the build was two lines and a success flag. I hit two specific hurdles that are worth spelling out so you do not repeat them.

Network Mismatch

The SDK supports both mainnet and preprod environments. I spent a solid chunk of time debugging a domain that “did not exist.” The name was correct. The code looked right. The provider was running. The problem was that my script was querying preprod while the domain itself was registered on mainnet. The error looked like a missing domain, but it was really a missing network context.

If you are resolving a name and getting back a failure, check the provider settings before you debug anything else. Make sure your networkId matches the network where the domain is actually minted. This is the kind of mistake that feels obvious in retrospect but is genuinely hard to spot when you are assuming the contract logic is the issue.

Serialization Pain

The data that comes back from the SDK is not standard JavaScript. It contains BigInt values and Map objects. If you try to pipe that straight into JSON.stringify to send it to a browser, it will throw or silently drop data. BigInt has no native JSON representation, and Map does not serialize the way plain objects do.

I ended up writing a custom serializer. It walks the result object, converts BigInt values to strings, and transforms Map instances into regular objects before the response leaves the server. If you are building an API that serves Midnight data to a frontend, plan for this step early. Do not assume the SDK output is immediately frontend-friendly just because it is JavaScript.

The Architecture

میں نے ٹیکنالوجی اسٹیک کو جان بوجھ کر سادہ رکھا۔ بیک اینڈ ایک Node سرور ہے جو Express چلا رہا ہے۔ یہ @midnames/sdk کو امپورٹ کرتا ہے، ریزولوشن لاجک چلاتا ہے، سیریلائزیشن کی پیچیدگیوں کو سنبھالتا ہے، اور صاف ستھرا JSON فراہم کرتا ہے۔ فرنٹ اینڈ سادہ HTML اور vanilla JavaScript ہے۔ کوئی بلڈ سٹیپ نہیں۔ کوئی فریم ورک نہیں۔ کوئی والٹ ایڈاپٹر نہیں۔

میں نے چند عملی وجوہات کی بنا پر SDK کو براؤزر کے بجائے بیک اینڈ پر چلانے کا فیصلہ کیا۔ یہ کسی بھی provider configuration کو کلائنٹ سے دور رکھتا ہے، مجھے سیریلائزیشن کی الجھن کو ٹھیک کرنے کے لیے ایک ہی جگہ فراہم کرتا ہے، اور اس کا مطلب ہے کہ فرنٹ اینڈ کو صرف ڈیٹا حاصل کرنے اور اسے دکھانے (render) کی ضرورت ہے۔

یہاں وہ حصہ ہے جس نے مجھے سب سے زیادہ حیران کیا: کسی نام کو ریزولیو (resolve) کرنا ایک عوامی ریڈ آپریشن (public read operation) ہے۔ آپ کو والٹ کنکشن کی ضرورت نہیں ہے۔ آپ کو کسی دستخط (signature) کی ضرورت نہیں ہے۔ آپ کو صارف کے کسی بھی چیز کے ساتھ لاگ ان کرنے کی ضرورت نہیں ہے۔ اگر ڈومین موجود ہے، تو کنٹریکٹ اسٹیٹ (contract state) ہر اس شخص کے لیے قابلِ رسائی ہے جو اسے پوچھے گا۔ یہ عام web3 فلو سے ایک اہم فرق ہے جہاں ہر تعامل "connect wallet" سے شروع ہوتا ہے۔ Midnight پر شناخت پڑھنا بالکل اسی طرح بغیر کسی اجازت کے (permissionless) ہے جیسے کسی عوامی ویب سائٹ کو پڑھنا بغیر کسی اجازت کے ہے۔

اصل نچوڑ

اس ویور (viewer) کو بنانے سے مجھے یاد آیا کہ بلاک چین ڈویلپمنٹ کا مشکل ترین حصہ شاذ و نادر ہی خود بلاک چین ہوتا ہے۔ Midnight نے پہلے ہی مشکل مسئلہ حل کر دیا ہے: لوگوں کو مرکزی ڈیٹا بیس کے بغیر اپنے نام اور پروفائل کا مالک بننے دینا۔ ایک بلڈر کے نقطہ نظر سے، مشکل حصہ یہ یاد رکھنا تھا کہ میں کس نیٹ ورک کی طرف اشارہ کر رہا ہوں اور ڈیٹا ٹائپس کو صاف کرنے کے لیے ایک ہیلپر فنکشن لکھنا تھا۔

پروٹوکول آپ کو پورٹیبل شناخت (portable identity) فراہم کرتا ہے۔ ایک ڈویلپر کے طور پر آپ کا کام صرف اسے صحیح طریقے سے پڑھنا اور صارف کے کام میں مداخلت نہ کرنا ہے۔ آرکیٹیکچر کو سادہ رکھیں، چین سے متعلقہ لاجک کو UI سے الگ رکھیں، اور عوامی ریڈز (public reads) کو ویسا ہی سمجھیں جیسے وہ ہیں: عام ڈیٹا بیس کوئریز جو محض ایک تقسیم شدہ لیجر (distributed ledger) پر موجود ہیں۔

اگر آپ کوڈ دیکھنا چاہتے ہیں یا اسے خود چلانا چاہتے ہیں، تو مکمل سورس یہاں دستیاب ہے: https://github.com/tomiin/midnames-profile-viewer.