Skip to main content

First Request

Let's make requests with the SDK.

Anonymous Request

import { ATVClient } from '@atv-eth/x402-sdk';

const client = new ATVClient({
privateKey: process.env.WALLET_KEY,
});

// Uses free tier first
const profile = await client.getProfile('vitalik.eth');
console.log(profile);

Authenticated Request (SIWE)

// Sign in for 2x rate limits
await client.signIn();
console.log('Authenticated:', client.isAuthenticated);

// Now all requests are authenticated
const me = await client.me();
const usage = await client.myUsage();
console.log(`Usage: ${usage.used}/${usage.limit}`);

Handling Responses

Success

const profile = await client.getProfile('nick.eth');

console.log('Name:', profile.name);
console.log('Address:', profile.address);
console.log('Avatar:', profile.avatar);
console.log('Twitter:', profile.records?.twitter);

Errors

try {
const profile = await client.getProfile('nonexistent12345.eth');
} catch (error) {
console.log('Error code:', error.code); // "ENS_NOT_FOUND"
console.log('Error message:', error.message);
}

Complete Example

import { ATVClient } from '@atv-eth/x402-sdk';

async function main() {
const client = new ATVClient({
privateKey: process.env.WALLET_KEY,
});

// Optional: authenticate for better limits
await client.signIn();

// Get ENS profile
const profile = await client.getProfile('vitalik.eth');
console.log('Profile:', profile);

// Get wallet tokens
const tokens = await client.getTokens(profile.address);
console.log('Tokens:', tokens.length);

// Get gas prices
const gas = await client.getGas();
console.log('Gas:', gas);

// Check usage
const usage = await client.myUsage();
console.log(`Used ${usage.used} of ${usage.limit} calls`);
}

main().catch(console.error);

Next Steps