2023-05-03 22:56:02 +03:00
|
|
|
import { ChainId } from '@/types'
|
2023-06-15 17:20:15 +03:00
|
|
|
|
|
|
|
import { getProvider } from '@/services'
|
2023-05-03 22:56:02 +03:00
|
|
|
|
|
|
|
async function getEnsOwner(ensName: string, chainId: ChainId) {
|
|
|
|
try {
|
2023-06-15 17:20:15 +03:00
|
|
|
const { provider } = getProvider(chainId)
|
|
|
|
const ownerAddress = await provider.resolveName(ensName)
|
2023-05-03 22:56:02 +03:00
|
|
|
|
2023-06-15 17:20:15 +03:00
|
|
|
return ownerAddress || undefined
|
2023-05-03 22:56:02 +03:00
|
|
|
} 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 }
|