ens-avatar
Avatar resolver library for both nodejs and browser.
Note!: ENS-Avatar >= 1.0.0 is only compatible with ethers v6. If your project is using v5, keep your ens-avatar on latest 0.x version.
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' });
Marketplace Api Keys (Default: {})
const avt = new AvatarResolver(provider, {
apiKey: {
opensea: 'YOUR_API_KEY'
}
});
URL DenyList (Default: [])
const avt = new AvatarResolver(provider, { urlDenyList: ['https://maliciouswebsite.com'] });
Demo
node example/node.js ENS_NAME
yarn build:demo
http-server example