relayers-network-ui/services/ENS/ens.ts
Theo 5a7839eb28 Fix function that gets owner of ENS domain by domain name:
with new ENS Name Wrapper simple call of function 'owner' from ensRegistry contract returned not owner, but wrapper address. Changed to function ethers.provider.resolveName, that returns real owner address
2023-06-15 07:20:15 -07:00

37 lines
833 B
TypeScript

import { ChainId } from '@/types'
import { getProvider } from '@/services'
async function getEnsOwner(ensName: string, chainId: ChainId) {
try {
const { provider } = getProvider(chainId)
const ownerAddress = await provider.resolveName(ensName)
return ownerAddress || undefined
} catch (err) {
return undefined
}
}
async function getNameFromHash(ensHash: string) {
try {
const response = await fetch('https://api.thegraph.com/subgraphs/name/ensdomains/ens', {
body: JSON.stringify({
query: `{
domain(id: "${ensHash}") {
name
}
}`,
}),
method: 'POST',
})
const { data } = await response.json()
return data.domain.name
} catch (err) {
throw new Error(err.message)
}
}
export { getEnsOwner, getNameFromHash }