Integration
Information for integrating with the Alephium Name Service protocol.
ANS SDK
Install
Usage
React snippet example
Last updated
Information for integrating with the Alephium Name Service protocol.
Last updated
npm install @alph-name-service/ans-sdkimport { ANS } from "@alph-name-service/ans-sdk";
const ans = new ANS("mainnet");
const profile = await ans.getProfile("<address>");
// returns {name: "...", imgUri: "..."}
// if profile exists, undefined otherwise
const record = await ans.getRecord("<name>");
// returns {owner: ..., manager: ..., ttl: ...}
// if name exists, undefined otherwise
const resolvedAddress = await ans.resolveName("<name>");
// returns the resolved address string
// if name exists, undefined otherwiseimport { ANS } from "@alph-name-service/ans-sdk";
const [ansName, setAnsName] = useState<string>();
const [ansUri, setAnsUri] = useState<string>();
const fetchAnsProfile = async (address) => {
try {
const ans = new ANS('mainnet');
const profile = await ans.getProfile(address);
if (profile?.name) {
setAnsName(profile.name);
}
if (profile?.imgUri) {
setAnsUri(profile.imgUri);
}
} catch (error) {
console.error('Error fetching ANS:', error);
}
};
useEffect(() => {
if (wallet?.account?.address) {
fetchAnsProfile(wallet.account.address);
}
}, [wallet?.account?.address]);