ens-avatar
Avatar resolver library for both nodejs and browser.
Getting started
Prerequisites
- Have your web3 provider ready (web3.js, ethers.js)
- [Only for node env] Have jsdom installed.
And good to go!
Installation
npm i @ensdomains/ens-avatar
yarn add @ensdomains/ens-avatar
Usage
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { AvatarResolver, utils as avtUtils } from '@ensdomains/ens-avatar';
const provider = new StaticJsonRpcProvider(
...
);
...
async function getAvatar() {
const avt = new AvatarResolver(provider);
const avatarURI = await avt.getAvatar('tanrikulu.eth', { });
}
async function getAvatarMetadata() {
const avt = new AvatarResolver(provider);
const avatarMetadata = await avt.getMetadata('tanrikulu.eth');
const avatarURI = avtUtils.getImageURI({ metadata });
}
Supported avatar specs
NFTs
URIs
Options
Cache (Default: Disabled)
const avt = new AvatarResolver(provider, { cache: 300 });
Custom IPFS Gateway (Default: https://ipfs.io)
const avt = new AvatarResolver(provider, { ipfs: 'https://dweb.link' });
const avt = new AvatarResolver(provider, { arweave: 'https://arweave.net' });
Demo
node example/node.js ENS_NAME
yarn build:demo
http-server example