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
This commit is contained in:
parent
0d8c85f49f
commit
5a7839eb28
@ -1,21 +1,13 @@
|
|||||||
import { BigNumber } from 'ethers'
|
|
||||||
import { namehash } from 'ethers/lib/utils'
|
|
||||||
|
|
||||||
import { ChainId } from '@/types'
|
import { ChainId } from '@/types'
|
||||||
import { getEnsRegistry } from '@/contracts'
|
|
||||||
|
import { getProvider } from '@/services'
|
||||||
|
|
||||||
async function getEnsOwner(ensName: string, chainId: ChainId) {
|
async function getEnsOwner(ensName: string, chainId: ChainId) {
|
||||||
try {
|
try {
|
||||||
const node = namehash(ensName)
|
const { provider } = getProvider(chainId)
|
||||||
const ensContract = getEnsRegistry(chainId)
|
const ownerAddress = await provider.resolveName(ensName)
|
||||||
|
|
||||||
const owner = await ensContract.callStatic.owner(node)
|
return ownerAddress || undefined
|
||||||
|
|
||||||
if (BigNumber.from(owner).isZero()) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
return owner
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user