Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/actions/ens/getEnsName.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const client = anvilMainnet.getClient()

beforeAll(async () => {
await reset(client, {
blockNumber: 23_093_073n,
blockNumber: 25_382_400n,
jsonRpcUrl: anvilMainnet.forkUrl,
})
await setVitalikResolver()
Expand Down Expand Up @@ -138,6 +138,22 @@ describe('primary name with non-contract resolver', () => {
})
})

test('primary name with offchain resolver', async () => {
await expect(
getEnsName(client, {
address: '0xEB4200f750335eFb67E726485445d302D64B1c8A',
}),
).resolves.toMatchInlineSnapshot('"test.antistupid.com"')
})

test('unnormalized primary name', async () => {
await expect(
getEnsName(client, {
address: '0xb404Af9A235Be881335d8898B5B487dc9Cd5ed9D',
}),
).resolves.toMatchInlineSnapshot('null')
})

describe('http error', () => {
let server: Awaited<ReturnType<typeof createHttpServer>> | undefined
beforeAll(async () => {
Expand Down
11 changes: 11 additions & 0 deletions src/actions/ens/getEnsName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
type ReadContractParameters,
readContract,
} from '../public/readContract.js'
import { normalize } from '../../ens/index.js'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would it take for ens-normalize to be much lighter in terms of bundle size? :D

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an async context, switch to dynamic import and guard it with a regex that covers common cases?

Now that LLMs are pretty good, I could revisit the normalization compression logic.

@adraffy adraffy Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, can you tell me what minimum JS engine you're supporting? There is an approach that leverages regex \p.

The actual library logic is extremely small — nearly all of the size is the compressed Unicode data.


I've been contemplating making a ens-normalize.ts variant since the current library is basically the research version and all of the other language ports are clean and typed.

@adraffy adraffy Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could I get some input on this? @jxom

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


export type GetEnsNameParameters = Prettify<
Pick<ReadContractParameters, 'blockNumber' | 'blockTag'> & {
Expand Down Expand Up @@ -131,10 +132,20 @@ export async function getEnsName<chain extends Chain | undefined>(

const [name] = await readContractAction(readContractParameters)

if (!isNormalized(name)) return null

return name || null
} catch (err) {
if (strict) throw err
if (isNullUniversalResolverError(err)) return null
throw err
}
}

function isNormalized(name: string) {
try {
return name === normalize(name)
} catch {
return
}
}
Loading