-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
565 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { providers } from "ethers"; | ||
|
||
const main = async () => { | ||
const rpcUrl = "https://rpc.ankr.com/eth"; | ||
const provider = new providers.JsonRpcProvider(rpcUrl); | ||
|
||
const ensName = await provider.resolveName("zapaz.eth"); | ||
console.log("ensName:", ensName); | ||
|
||
const ensAvatar = await provider.getAvatar("zapaz.eth"); | ||
console.log("ensAvatar:", ensAvatar); | ||
}; | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { createPublicClient, http } from "viem"; | ||
import { normalize } from "viem/ens"; | ||
import { mainnet } from "viem/chains"; | ||
|
||
export const publicClient = createPublicClient({ | ||
chain: mainnet, | ||
transport: http() | ||
}); | ||
|
||
const address = "0x981ab0D817710d8FFFC5693383C00D985A3BDa38"; | ||
|
||
const main = async () => { | ||
const ensName = await publicClient.getEnsName({ address }); | ||
console.log("ensName :", ensName); | ||
|
||
if (!ensName) return; | ||
|
||
const ensAvatar = await publicClient.getEnsAvatar({ | ||
name: normalize(ensName) | ||
}); | ||
console.log("ensAvatar:", ensAvatar); | ||
}; | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Address, createPublicClient, http } from "viem"; | ||
import { normalize } from "viem/ens"; | ||
import { mainnet } from "viem/chains"; | ||
|
||
const publicClient = createPublicClient({ | ||
chain: mainnet, | ||
transport: http() | ||
}); | ||
|
||
const ens = (() => { | ||
const getName = async (address: string): Promise<string> => { | ||
let name: string | null = null; | ||
|
||
try { | ||
name = await publicClient.getEnsName({ address: address as Address }); | ||
} catch (e) { | ||
console.error("ENS lookupAddress not found"); | ||
} | ||
|
||
console.info("getName", address, "=>", name); | ||
return name || address || ""; | ||
}; | ||
|
||
const getAvatar = async (address: string): Promise<string> => { | ||
let avatar: string | null = null; | ||
|
||
try { | ||
// avatar = await ensProvider.getAvatar(address); | ||
avatar = await publicClient.getEnsAvatar({ | ||
name: normalize(address) | ||
}); | ||
} catch (e) { | ||
console.error("ENS lookupAddress not found"); | ||
} | ||
|
||
console.info("getAvatar", address, "=>", avatar); | ||
return avatar || ""; | ||
}; | ||
|
||
return { getName, getAvatar }; | ||
})(); | ||
|
||
export { ens }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.