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 { getEnsRegistry } from '@/contracts'
|
||||
|
||||
import { getProvider } from '@/services'
|
||||
|
||||
async function getEnsOwner(ensName: string, chainId: ChainId) {
|
||||
try {
|
||||
const node = namehash(ensName)
|
||||
const ensContract = getEnsRegistry(chainId)
|
||||
const { provider } = getProvider(chainId)
|
||||
const ownerAddress = await provider.resolveName(ensName)
|
||||
|
||||
const owner = await ensContract.callStatic.owner(node)
|
||||
|
||||
if (BigNumber.from(owner).isZero()) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return owner
|
||||
return ownerAddress || undefined
|
||||
} catch (err) {
|
||||
return undefined
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user