Get Siwe Message
Get SIWE Message
This GET route returns a SIWE Message that users sign for authentication purposes.
Libraries such as viem or tools like Etherscan can be used to sign the message. Once signed, the message returns a signature that authenticates the user.
Parameters
address
(string): Your Ethereum address. This address should own the domain name you plan to use with NameStone.domain
(string)(optional): The domain sending the SIWE message. If not filled out, it defaults to namestone.xyz. The format should be "yourdomain.tld".uri
(string)(optional): The URI sending the SIWE message. If not filled out, it defaults to "https://namestone.xyz/api/public_v1/get-siwe-message"
Curl Example
curl -X GET \
'https://namestone.xyz/api/public_v1/get-siwe-message?address=0x57632Ba9A844af0AB7d5cdf98b0056c8d87e3A85'
SDK Example
import NameStone, { AuthenticationError, NetworkError } from "namestone-sdk";
// Initialize the NameStone instance
const ns = new NameStone();
// Define the SIWE message parameters
const address = "0x57632Ba9A844af0AB7d5cdf98b0056c8d87e3A85";
const domain = "yourdomain.tld"; // optional
const uri = "https://yourdomain.tld/api"; // optional
// Use an immediately invoked async function to allow top-level await
(async () => {
try {
const response = await ns.getSiweMessage({
address: address,
domain: domain, // optional parameter
uri: uri, // optional parameter
});
console.log("SIWE message received:", response);
// Example response message will look like:
// namestone.xyz wants you to sign in with your Ethereum account:
// 0x57632Ba9A844af0AB7d5cdf98b0056c8d87e3A85
// Sign this message to access protected endpoints.
// URI: https://namestone.xyz/api/public_v1/get-siwe-message
// Version: 1
// Chain ID: 1
// Nonce: b10ffd444b0a2d810377a3900ba6cd0422141306d158520f24b2805952ea589f9bd1bcbf2e353a14105830183472de5f
// Issued At: 2024-10-18T17:05:37.933Z
} catch (error) {
if (error instanceof NetworkError) {
console.error("Network error:", error.message);
} else {
console.error("An unexpected error occurred:", error);
}
}
})();
Example Return
Siwe message: namestone.xyz wants you to sign in with your Ethereum account:
0x57632Ba9A844af0AB7d5cdf98b0056c8d87e3A85
Sign this message to access protected endpoints.
URI: https://namestone.xyz/api/public_v1/get-siwe-message
Version: 1
Chain ID: 1
Nonce: b10ffd444b0a2d810377a3900ba6cd0422141306d158520f24b2805952ea589f9bd1bcbf2e353a14105830183472de5f
Issued At: 2024-10-18T17:05:37.933Z