πŸ“‡
ENS Profile Resolution
Resolve ENS Profiles for users signing into a service
Requirements
The user's linked Ethereum Name Service (ENS) information can be retrieved after their Ethereum address is known. After the user connects with their wallet but before they Sign-In with Ethereum, ENS information can be used to provide additional context to the user about which account is connected.
If the user completes Sign-In with Ethereum to authenticate, the ENS data resolved from their Ethereum address may be used as part of the authenticated session, such as checking that the address's default ENS name is alisha.eth before granting access to certain pages or resources.
The information can be retrieved using the ENS resolution methods in ethers:
import { ethers } from 'ethers';
​
const provider = new ethers.providers.EtherscanProvider()
const address = '0x9297A132AF2A1481441AB8dc1Ce6e243d879eaFD'
​
const ensName = await provider.lookupAddress(address)
const ensAvatarUrl = await provider.getAvatar(ensName)
​
const ensResolver = await provider.getResolver(ensName)
// You can fetch any key stored in their ENS profile.
const twitterHandle = await ensResolver.getText('com.twitter')
The user's Avatar location can be resolved using ensResolver.getText, butgetAvatar is recommended as it resolves NFT avatars to a URL.
The EtherscanProvider above uses a shared API key and is therefore rate-limited. For a production application, we strongly recommend using a new API key with Etherscan or another compatible provider.
Copy link