Resolver library
The resolver library provides tools for resolving identities to EVM addresses and keeping track of them in a cache
Quick start
import { getUserInfo } from "xmtp";
// Because user identifiers come in all shapes and sizes!
const identifier = "vitalik.eth"; // Could also be "0x123...", "@fabri", or even a website
const userInfo = await getUserInfo(identifier);
console.log(userInfo);
/*
{
ensDomain: 'vitalik.eth',
address: '0x1234...',
preferredName: 'vitalik.eth',
converseUsername: '',
avatar: 'https://...',
converseEndpoint: ''
}
*/Supported identifiers
- Ethereum Addresses : Example:
0x1234... - ENS Domains : Example:
vitalik.eth - Converse Usernames : Example:
@fabri - Inbox ID : Example:
0x1234...(Converse inbox ID) - Website Header Tag : Example:
https://example.comcontainingxmtp=0x1234... - Website TXT Record : Example:
meta="xmtp" content="0x1234..."
Returned UserInfo
The resolver always returns a UserInfo object with these fields:
| Field | Description |
|---|---|
| ensDomain | The user’s ENS domain (if any) |
| address | The Ethereum address |
| preferredName | Best name to display |
| converseUsername | The user’s Converse username (if any) |
| avatar | URL of the user’s profile picture (if any) |
| converseEndpoint | Endpoint for the user’s Converse profile |
Sending Messages
Here’s a quick snippet showing how you can utilize the resolver for your messaging:
// Example user message object
let textMessage: userMessage = {
message: "Hello, world!",
receivers: [
"0x123...", // Ethereum address
"vitalik.eth", // ENS
"@fabri", // Converse username
"https://example.com", // Website header tag or TXT record
],
originalMessage: message, // optional original reference
};
await xmtp.send(textMessage);Cache
Skip the repeated lookups—use the built-in cache to store user data. Clear it whenever you need a fresh slate:
import { userInfoCache } from "xmtp";
// Clear the entire cache:
userInfoCache.clear();
// Clear a specific address from the cache:
userInfoCache.clear("0x1234...");This makes repeated lookups lightning-fast, so you can focus on building cool stuff instead of waiting on network calls.