Skip to content

Instantly share code, notes, and snippets.

@mdtanrikulu
Last active December 15, 2022 23:18
Show Gist options
  • Save mdtanrikulu/3c88eef277acbf2bc246b370b258a2f0 to your computer and use it in GitHub Desktop.
Save mdtanrikulu/3c88eef277acbf2bc246b370b258a2f0 to your computer and use it in GitHub Desktop.
import { ENS } from "@ensdomains/ensjs"; // 3.0.0-alpha.39
import { providers } from "ethers"; // 5.7.2
const client = new ENS();
const provider = new providers.Web3Provider(window.ethereum, "goerli");
async function setENSAvatar() {
await client.setProvider(provider);
await provider.send("eth_requestAccounts", []);
const signer = provider.getSigner();
const address = await signer.getAddress();
console.log(address);
const ens = await provider.lookupAddress(address);
console.log(ens);
const tx = await client.setRecords(ens, {
records: {
contentHash: "ar://tnLgkAg70wsn9fSr1sxJKG_qcka1gJtmUwXm_3_lDaI"
}
});
await tx.wait();
}
export default function App() {
return (
<div>
<h1>Hello there! Click to set your avatar</h1>
<button
onClick={() => {
setENSAvatar();
}}
>
Set avatar
</button>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment