Cloudflare Worker that provides a simple API for fetching ENS profiles and avatars
[!NOTE] This is meant to be self-hosted. Follow the instructions below to deploy it to your own Cloudflare account.
Cloudflare Worker that provides a simple API for fetching ENS profiles and avatars. Built with ENSjs, heavily inspired by v3xlabs/enstate.
By default, all endpoints are cached for 10 minutes, then serve a stale response within the following 50 minutes while refreshing the cache in the background. Adjust these settings here. Avatars are cached for longer in most cases.
/name/:name
- Fetch a profile for an ENS name
texts
- keys of text records to fetch (comma-separated)coins
- coin types to fetch (comma-separated)/address/:address
- Fetch a profile for an Ethereum address, if it has a primary ENS name
texts
- keys of text records to fetch (comma-separated)coins
- coin types to fetch (comma-separated)/avatar/:name
- Fetch an avatar for an ENS name
width
- width of the avatar (default: 256)height
- height of the avatar (default: 256)fallback
- image URL to use if the ENS name has no avatar/batch/names
- Resolve a list of addresses from ENS names
names
- array of ENS namescoinType
(optional) - coin type to resolve (default: 60)/batch/addresses
- Resolve a list of primary ENS names from ETH addresses
addresses
- array of ETH addressesClone this repo
git clone https://github.com/gskril/ens-api.git
Install dependencies
yarn install
Set your environment variables (ETH RPC URL)
cp .dev.vars.example .dev.vars
Run the development server
yarn run dev
Sign into the Cloudflare CLI
npx wrangler login
Deploy the Worker
yarn && yarn run deploy
Set your ETH RPC environment variable
echo <VALUE> | npx wrangler secret put ETH_RPC
In order to enable avatar transformations, you will need to configure Cloudflare in a few ways:
A
record that points to 192.0.2.0
with any name you want as a subdomain.