Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@ensdomains/ens-avatar
Advanced tools
Avatar resolver library for both nodejs and browser.
Readme
Avatar resolver library for both nodejs and browser.
And good to go!
# npm
npm i @ensdomains/ens-avatar
# yarn
yarn add @ensdomains/ens-avatar
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { AvatarResolver, utils as avtUtils } from '@ensdomains/ens-avatar';
// const { JSDOM } = require('jsdom'); on nodejs
// const jsdom = new JSDOM().window; on nodejs
const provider = new StaticJsonRpcProvider(
...
);
...
async function getAvatar() {
const avt = new AvatarResolver(provider);
const avatarURI = await avt.getAvatar('tanrikulu.eth', { /* jsdomWindow: jsdom (on nodejs) */ });
// avatarURI = https://ipfs.io/ipfs/QmUShgfoZQSHK3TQyuTfUpsc8UfeNfD8KwPUvDBUdZ4nmR
}
async function getAvatarMetadata() {
const avt = new AvatarResolver(provider);
const avatarMetadata = await avt.getMetadata('tanrikulu.eth');
// avatarMetadata = { image: ... , uri: ... , name: ... , description: ... }
const avatarURI = avtUtils.getImageURI({ metadata /*, jsdomWindow: jsdom (on nodejs) */ });
// avatarURI = https://ipfs.io/ipfs/QmUShgfoZQSHK3TQyuTfUpsc8UfeNfD8KwPUvDBUdZ4nmR
}
const avt = new AvatarResolver(provider, { cache: 300 }); // 5 min response cache in memory
const avt = new AvatarResolver(provider, { ipfs: 'https://dweb.link' });
const avt = new AvatarResolver(provider, { arweave: 'https://arweave.net' });
const avt = new AvatarResolver(provider, {
apiKey: {
opensea: 'YOUR_API_KEY'
}
});
const avt = new AvatarResolver(provider, { urlDenyList: ['https://maliciouswebsite.com'] });
Create .env file with INFURA_KEY env variable
Build the library
Node example
node example/node.js ENS_NAME
yarn build:demo
http-server example
FAQs
Avatar resolver library for both nodejs and browser.
The npm package @ensdomains/ens-avatar receives a total of 697 weekly downloads. As such, @ensdomains/ens-avatar popularity was classified as not popular.
We found that @ensdomains/ens-avatar demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.