Get Started - SpaceID¶
How to Resolve a Name Using the Space ID SDK¶
Step 1: Setup Your Project¶
-
Install Node.js and npm Ensure you have Node.js and npm installed. You can download them from Node.js official website.
-
Create a New Project Open your terminal and create a new project directory:
mkdir spaceid-tutorial
cd spaceid-tutorial
npm init -y
Copy code
npm install @spaceid/sdk
Step 2: Write the Code to Resolve a Name¶
-
Create a JavaScript File Create a file named
resolveName.js
in your project directory. -
Import the Space ID SDK At the top of
resolveName.js
, import the Space ID SDK:
const { SpaceID } = require('@spaceid/sdk');
const spaceId = new SpaceID({
endpoint: 'https://api.spaceid.io', // API endpoint
apiKey: 'your_api_key' // Replace with your actual API key
});
- Resolve a Name Write a function to resolve a name using the SDK:
async function resolveName(name) {
try {
const result = await spaceId.resolveName(name);
console.log(`Address for ${name}: ${result.address}`);
} catch (error) {
console.error('Error resolving name:', error);
}
}
- Call the Function
Call the
resolveName
function with a sample name:
resolveName('example.eth');
Step 3: Run the Code¶
- Run the Script In your terminal, run the script:
node resolveName.js
Example Code¶
Here’s the complete code for resolveName.js:
const { SpaceID } = require('@spaceid/sdk');
const spaceId = new SpaceID({
endpoint: 'https://api.spaceid.io',
apiKey: 'your_api_key'
});
async function resolveName(name) {
try {
const result = await spaceId.resolveName(name);
console.log(`Address for ${name}: ${result.address}`);
} catch (error) {
console.error('Error resolving name:', error);
}
}
resolveName('example.eth');