Claim Name
Claim Name
This POST route is used to claim a name for a given address and domain. It will throw an error if the name has already been claimed.
URL Parameters
single_claim
(1 or 0): If this parameter is 1, each address can claim only one name.
Post Parameters
name
(string): The name being set, i.e., the "example" in example.testbrand.eth.domain
(string): The domain ("testbrand.eth").address
(string): The ethereum address the name points to.contenthash
(string)(Optional): The link for an ipfs or ipns website.text_records
(object)(Optional): An object containing key-value pairs representing the text records to be set.
Curl Example
curl -X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: YOUR_API_KEY' \
-d '{
"domain":"testbrand.eth",
"name":"example",
"address":"0xE997d9b785Dd99832d21b3Ce5A34fCacC6D53C57",
"text_records": {
"com.twitter": "namestonehq",
"com.github":"aslobodnik",
"com.discord":"superslobo",
"url":"https://www.namestone.xyz",
"location":"📍 nyc",
"description":"APIs are cool",
"avatar":"https://raw.githubusercontent.com/aslobodnik/profile/main/pic.jpeg"
}
}' \
https://namestone.xyz/api/public_v1/claim-name
SDK Example
import NameStone, { AuthenticationError, NetworkError, TextRecords } from 'namestone-sdk';
// Initialize the NameStone instance
const ns = new NameStone(<YOUR_API_KEY_HERE>);
// Define the text records
const textRecords: TextRecords = {
"com.twitter": "namestonehq",
"com.github": "aslobodnik",
"com.discord": "superslobo",
"url": "https://www.namestone.xyz",
"location": "📍 nyc",
"description": "APIs are cool",
"avatar": "https://raw.githubusercontent.com/aslobodnik/profile/main/pic.jpeg"
};
// Use an immediately invoked async function to allow top-level await
(async () => {
try {
const response = await ns.claimName(
{
name: "example",
domain: "testbrand.eth",
address: "0xE997d9b785Dd99832d21b3Ce5A34fCacC6D53C57",
text_records:textRecords,
single_claim:0
}
);
console.log("Name set successfully", response);
} catch (error) {
if (error instanceof AuthenticationError) {
console.error("Authentication failed:", error.message);
} else if (error instanceof NetworkError) {
console.error("Network error:", error.message);
} else {
console.error("An unexpected error occurred:", error);
}
}
})();