ethers/lib/utils#namehash TypeScript Examples
The following examples show how to use
ethers/lib/utils#namehash.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useENSAddress.ts From interface-v2 with GNU General Public License v3.0 | 6 votes |
/**
* Does a lookup for an ENS name to find its address.
*/
export default function useENSAddress(
ensName?: string | null,
): { loading: boolean; address: string | null } {
const debouncedName = useDebounce(ensName, 200);
const ensNodeArgument = useMemo(() => {
if (!debouncedName) return [undefined];
try {
return debouncedName ? [namehash(debouncedName)] : [undefined];
} catch (error) {
return [undefined];
}
}, [debouncedName]);
const registrarContract = useENSRegistrarContract(false);
const resolverAddress = useSingleCallResult(
registrarContract,
'resolver',
ensNodeArgument,
);
const resolverAddressResult = resolverAddress.result?.[0];
const resolverContract = useENSResolverContract(
resolverAddressResult && !isZero(resolverAddressResult)
? resolverAddressResult
: undefined,
false,
);
const addr = useSingleCallResult(resolverContract, 'addr', ensNodeArgument);
const changed = debouncedName !== ensName;
return {
address: changed ? null : addr.result?.[0] ?? null,
loading: changed || resolverAddress.loading || addr.loading,
};
}
Example #2
Source File: useENSContentHash.ts From interface-v2 with GNU General Public License v3.0 | 6 votes |
/**
* Does a lookup for an ENS name to find its contenthash.
*/
export default function useENSContentHash(
ensName?: string | null,
): { loading: boolean; contenthash: string | null } {
const ensNodeArgument = useMemo(() => {
if (!ensName) return [undefined];
try {
return ensName ? [namehash(ensName)] : [undefined];
} catch (error) {
return [undefined];
}
}, [ensName]);
const registrarContract = useENSRegistrarContract(false);
const resolverAddressResult = useSingleCallResult(
registrarContract,
'resolver',
ensNodeArgument,
);
const resolverAddress = resolverAddressResult.result?.[0];
const resolverContract = useENSResolverContract(
resolverAddress && isZero(resolverAddress) ? undefined : resolverAddress,
false,
);
const contenthash = useSingleCallResult(
resolverContract,
'contenthash',
ensNodeArgument,
);
return {
contenthash: contenthash.result?.[0] ?? null,
loading: resolverAddressResult.loading || contenthash.loading,
};
}
Example #3
Source File: useENSName.ts From interface-v2 with GNU General Public License v3.0 | 6 votes |
/**
* Does a reverse lookup for an address to find its ENS name.
* Note this is not the same as looking up an ENS name to find an address.
*/
export default function useENSName(
address?: string,
): { ENSName: string | null; loading: boolean } {
const debouncedAddress = useDebounce(address, 200);
const ensNodeArgument = useMemo(() => {
if (!debouncedAddress || !isAddress(debouncedAddress)) return [undefined];
try {
return debouncedAddress
? [namehash(`${debouncedAddress.toLowerCase().substr(2)}.addr.reverse`)]
: [undefined];
} catch (error) {
return [undefined];
}
}, [debouncedAddress]);
const registrarContract = useENSRegistrarContract(false);
const resolverAddress = useSingleCallResult(
registrarContract,
'resolver',
ensNodeArgument,
);
const resolverAddressResult = resolverAddress.result?.[0];
const resolverContract = useENSResolverContract(
resolverAddressResult && !isZero(resolverAddressResult)
? resolverAddressResult
: undefined,
false,
);
const name = useSingleCallResult(resolverContract, 'name', ensNodeArgument);
const changed = debouncedAddress !== address;
return {
ENSName: changed ? null : name.result?.[0] ?? null,
loading: changed || resolverAddress.loading || name.loading,
};
}
Example #4
Source File: resolveENSContentHash.ts From interface-v2 with GNU General Public License v3.0 | 6 votes |
/**
* Fetches and decodes the result of an ENS contenthash lookup on mainnet to a URI
* @param ensName to resolve
* @param provider provider to use to fetch the data
*/
export default async function resolveENSContentHash(
ensName: string,
provider: Provider,
): Promise<string> {
const ensRegistrarContract = new Contract(
REGISTRAR_ADDRESS,
REGISTRAR_ABI,
provider,
);
const hash = namehash(ensName);
const resolverAddress = await ensRegistrarContract.resolver(hash);
return resolverContract(resolverAddress, provider).contenthash(hash);
}
Example #5
Source File: useENSAddress.ts From sybil-interface with GNU General Public License v3.0 | 6 votes |
/**
* Does a lookup for an ENS name to find its address.
*/
export default function useENSAddress(ensName?: string | null): { loading: boolean; address: string | null } {
const debouncedName = useDebounce(ensName, 200)
const ensNodeArgument = useMemo(() => {
if (!debouncedName) return [undefined]
try {
return debouncedName ? [namehash(debouncedName)] : [undefined]
} catch (error) {
return [undefined]
}
}, [debouncedName])
const registrarContract = useENSRegistrarContract(false)
const resolverAddress = useSingleCallResult(registrarContract, 'resolver', ensNodeArgument)
const resolverAddressResult = resolverAddress.result?.[0]
const resolverContract = useENSResolverContract(
resolverAddressResult && !isZero(resolverAddressResult) ? resolverAddressResult : undefined,
false
)
const addr = useSingleCallResult(resolverContract, 'addr', ensNodeArgument)
const changed = debouncedName !== ensName
return {
address: changed ? null : addr.result?.[0] ?? null,
loading: changed || resolverAddress.loading || addr.loading,
}
}
Example #6
Source File: useENSContentHash.ts From sybil-interface with GNU General Public License v3.0 | 6 votes |
/**
* Does a lookup for an ENS name to find its contenthash.
*/
export default function useENSContentHash(ensName?: string | null): { loading: boolean; contenthash: string | null } {
const ensNodeArgument = useMemo(() => {
if (!ensName) return [undefined]
try {
return ensName ? [namehash(ensName)] : [undefined]
} catch (error) {
return [undefined]
}
}, [ensName])
const registrarContract = useENSRegistrarContract(false)
const resolverAddressResult = useSingleCallResult(registrarContract, 'resolver', ensNodeArgument)
const resolverAddress = resolverAddressResult.result?.[0]
const resolverContract = useENSResolverContract(
resolverAddress && isZero(resolverAddress) ? undefined : resolverAddress,
false
)
const contenthash = useSingleCallResult(resolverContract, 'contenthash', ensNodeArgument)
return {
contenthash: contenthash.result?.[0] ?? null,
loading: resolverAddressResult.loading || contenthash.loading,
}
}
Example #7
Source File: useENSName.ts From sybil-interface with GNU General Public License v3.0 | 6 votes |
/**
* Does a reverse lookup for an address to find its ENS name.
* Note this is not the same as looking up an ENS name to find an address.
*/
export default function useENSName(address?: string): { ENSName: string | null; loading: boolean } {
const debouncedAddress = useDebounce(address, 200)
const ensNodeArgument = useMemo(() => {
if (!debouncedAddress || !isAddress(debouncedAddress)) return [undefined]
try {
return debouncedAddress ? [namehash(`${debouncedAddress.toLowerCase().substr(2)}.addr.reverse`)] : [undefined]
} catch (error) {
return [undefined]
}
}, [debouncedAddress])
const registrarContract = useENSRegistrarContract(false)
const resolverAddress = useSingleCallResult(registrarContract, 'resolver', ensNodeArgument)
const resolverAddressResult = resolverAddress.result?.[0]
const resolverContract = useENSResolverContract(
resolverAddressResult && !isZero(resolverAddressResult) ? resolverAddressResult : undefined,
false
)
const name = useSingleCallResult(resolverContract, 'name', ensNodeArgument)
const changed = debouncedAddress !== address
return {
ENSName: changed ? null : name.result?.[0] ?? null,
loading: changed || resolverAddress.loading || name.loading,
}
}
Example #8
Source File: resolveENSContentHash.ts From sybil-interface with GNU General Public License v3.0 | 6 votes |
/**
* Fetches and decodes the result of an ENS contenthash lookup on mainnet to a URI
* @param ensName to resolve
* @param provider provider to use to fetch the data
*/
export default async function resolveENSContentHash(ensName: string, provider: Provider): Promise<string> {
const ensRegistrarContract = new Contract(REGISTRAR_ADDRESS, REGISTRAR_ABI, provider)
const hash = namehash(ensName)
const resolverAddress = await ensRegistrarContract.resolver(hash)
return resolverContract(resolverAddress, provider).contenthash(hash)
}
Example #9
Source File: useENSAddress.ts From cheeseswap-interface with GNU General Public License v3.0 | 6 votes |
/**
* Does a lookup for an ENS name to find its address.
*/
export default function useENSAddress(ensName?: string | null): { loading: boolean; address: string | null } {
const debouncedName = useDebounce(ensName, 200)
const ensNodeArgument = useMemo(() => {
if (!debouncedName) return [undefined]
try {
return debouncedName ? [namehash(debouncedName)] : [undefined]
} catch (error) {
return [undefined]
}
}, [debouncedName])
const registrarContract = useENSRegistrarContract(false)
const resolverAddress = useSingleCallResult(registrarContract, 'resolver', ensNodeArgument)
const resolverAddressResult = resolverAddress.result?.[0]
const resolverContract = useENSResolverContract(
resolverAddressResult && !isZero(resolverAddressResult) ? resolverAddressResult : undefined,
false
)
const addr = useSingleCallResult(resolverContract, 'addr', ensNodeArgument)
const changed = debouncedName !== ensName
return {
address: changed ? null : addr.result?.[0] ?? null,
loading: changed || resolverAddress.loading || addr.loading
}
}
Example #10
Source File: useENSContentHash.ts From cheeseswap-interface with GNU General Public License v3.0 | 6 votes |
/**
* Does a lookup for an ENS name to find its contenthash.
*/
export default function useENSContentHash(ensName?: string | null): { loading: boolean; contenthash: string | null } {
const ensNodeArgument = useMemo(() => {
if (!ensName) return [undefined]
try {
return ensName ? [namehash(ensName)] : [undefined]
} catch (error) {
return [undefined]
}
}, [ensName])
const registrarContract = useENSRegistrarContract(false)
const resolverAddressResult = useSingleCallResult(registrarContract, 'resolver', ensNodeArgument)
const resolverAddress = resolverAddressResult.result?.[0]
const resolverContract = useENSResolverContract(
resolverAddress && isZero(resolverAddress) ? undefined : resolverAddress,
false
)
const contenthash = useSingleCallResult(resolverContract, 'contenthash', ensNodeArgument)
return {
contenthash: contenthash.result?.[0] ?? null,
loading: resolverAddressResult.loading || contenthash.loading
}
}
Example #11
Source File: useENSName.ts From cheeseswap-interface with GNU General Public License v3.0 | 6 votes |
/**
* Does a reverse lookup for an address to find its ENS name.
* Note this is not the same as looking up an ENS name to find an address.
*/
export default function useENSName(address?: string): { ENSName: string | null; loading: boolean } {
const debouncedAddress = useDebounce(address, 200)
const ensNodeArgument = useMemo(() => {
if (!debouncedAddress || !isAddress(debouncedAddress)) return [undefined]
try {
return debouncedAddress ? [namehash(`${debouncedAddress.toLowerCase().substr(2)}.addr.reverse`)] : [undefined]
} catch (error) {
return [undefined]
}
}, [debouncedAddress])
const registrarContract = useENSRegistrarContract(false)
const resolverAddress = useSingleCallResult(registrarContract, 'resolver', ensNodeArgument)
const resolverAddressResult = resolverAddress.result?.[0]
const resolverContract = useENSResolverContract(
resolverAddressResult && !isZero(resolverAddressResult) ? resolverAddressResult : undefined,
false
)
const name = useSingleCallResult(resolverContract, 'name', ensNodeArgument)
const changed = debouncedAddress !== address
return {
ENSName: changed ? null : name.result?.[0] ?? null,
loading: changed || resolverAddress.loading || name.loading
}
}
Example #12
Source File: resolveENSContentHash.ts From cheeseswap-interface with GNU General Public License v3.0 | 6 votes |
/**
* Fetches and decodes the result of an ENS contenthash lookup on mainnet to a URI
* @param ensName to resolve
* @param provider provider to use to fetch the data
*/
export default async function resolveENSContentHash(ensName: string, provider: Provider): Promise<string> {
const ensRegistrarContract = new Contract(REGISTRAR_ADDRESS, REGISTRAR_ABI, provider)
const hash = namehash(ensName)
const resolverAddress = await ensRegistrarContract.resolver(hash)
return resolverContract(resolverAddress, provider).contenthash(hash)
}
Example #13
Source File: useENSAddress.ts From glide-frontend with GNU General Public License v3.0 | 6 votes |
/**
* Does a lookup for an ENS name to find its address.
*/
export default function useENSAddress(ensName?: string | null): { loading: boolean; address: string | null } {
const debouncedName = useDebounce(ensName, 200)
const ensNodeArgument = useMemo(() => {
if (!debouncedName) return [undefined]
try {
return debouncedName ? [namehash(debouncedName)] : [undefined]
} catch (error) {
return [undefined]
}
}, [debouncedName])
const registrarContract = useENSRegistrarContract(false)
const resolverAddress = useSingleCallResult(registrarContract, 'resolver', ensNodeArgument)
const resolverAddressResult = resolverAddress.result?.[0]
const resolverContract = useENSResolverContract(
resolverAddressResult && !isZero(resolverAddressResult) ? resolverAddressResult : undefined,
false,
)
const addr = useSingleCallResult(resolverContract, 'addr', ensNodeArgument)
const changed = debouncedName !== ensName
return {
address: changed ? null : addr.result?.[0] ?? null,
loading: changed || resolverAddress.loading || addr.loading,
}
}
Example #14
Source File: useENSContentHash.ts From glide-frontend with GNU General Public License v3.0 | 6 votes |
/**
* Does a lookup for an ENS name to find its contenthash.
*/
export default function useENSContentHash(ensName?: string | null): { loading: boolean; contenthash: string | null } {
const ensNodeArgument = useMemo(() => {
if (!ensName) return [undefined]
try {
return ensName ? [namehash(ensName)] : [undefined]
} catch (error) {
return [undefined]
}
}, [ensName])
const registrarContract = useENSRegistrarContract(false)
const resolverAddressResult = useSingleCallResult(registrarContract, 'resolver', ensNodeArgument)
const resolverAddress = resolverAddressResult.result?.[0]
const resolverContract = useENSResolverContract(
resolverAddress && isZero(resolverAddress) ? undefined : resolverAddress,
false,
)
const contenthash = useSingleCallResult(resolverContract, 'contenthash', ensNodeArgument)
return {
contenthash: contenthash.result?.[0] ?? null,
loading: resolverAddressResult.loading || contenthash.loading,
}
}
Example #15
Source File: useENSName.ts From glide-frontend with GNU General Public License v3.0 | 6 votes |
/**
* Does a reverse lookup for an address to find its ENS name.
* Note this is not the same as looking up an ENS name to find an address.
*/
export default function useENSName(address?: string): { ENSName: string | null; loading: boolean } {
const debouncedAddress = useDebounce(address, 200)
const ensNodeArgument = useMemo(() => {
if (!debouncedAddress || !isAddress(debouncedAddress)) return [undefined]
try {
return debouncedAddress ? [namehash(`${debouncedAddress.toLowerCase().substr(2)}.addr.reverse`)] : [undefined]
} catch (error) {
return [undefined]
}
}, [debouncedAddress])
const registrarContract = useENSRegistrarContract(false)
const resolverAddress = useSingleCallResult(registrarContract, 'resolver', ensNodeArgument)
const resolverAddressResult = resolverAddress.result?.[0]
const resolverContract = useENSResolverContract(
resolverAddressResult && !isZero(resolverAddressResult) ? resolverAddressResult : undefined,
false,
)
const name = useSingleCallResult(resolverContract, 'name', ensNodeArgument)
const changed = debouncedAddress !== address
return {
ENSName: changed ? null : name.result?.[0] ?? null,
loading: changed || resolverAddress.loading || name.loading,
}
}