# Integration

## ANS SDK

Use the ANS SDK to integrate in your JS/TS projects.

{% embed url="<https://www.npmjs.com/package/@alph-name-service/ans-sdk>" %}

## Install

```
npm install @alph-name-service/ans-sdk
```

### Usage

```javascript
import { 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 otherwise
```

If you want to integrate within a more involved use-case where you need to batch and get info for multiple addresses per request, feel free to reach out in Discord, Telegram or Twitter.

## React snippet example

```javascript
import { 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]);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://alephium-name-service.gitbook.io/ans/integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
