Signing requests for wallet mapping API

Introduction

The Wallet Mapping API allows users to associate blockchain wallet addresses with domain names. This document explains how to properly sign requests for various operations in the API.

Authentication

All API requests require:

  • An API key provided in the header as 'api-key'

  • A valid EIP-712 signature for the operation being performed

API Endpoints

1. Set Wallet Mapping

Associates a blockchain wallet address with a domain for a specific chain/symbol.

// Function to set a wallet mapping
async function setWalletMapping(symbol, name) {
  const payload = {
    domain: name,
    symbol,
    address: wallet.address,
    signatureExpiresAt: Date.now() + 5 * 60 * 1000, // 5 minutes
  };
  
  const signature = await wallet.signTypedData(
    SignDomain, 
    SetWeb3RecordTypes, 
    payload
  );
  
  return fetch(`https://api-public.d3.app/v1/domain/${name}/records/web3`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'api-key': API_KEY,
    },
    body: JSON.stringify({
      symbol,
      address: wallet.address,
      signature,
      signatureExpiresAt: payload.signatureExpiresAt,
    }),
  });
}

The SignDomain and SetWeb3RecordTypes constants are defined as:

Example

2. Delete Wallet Mapping

Removes the association between a wallet address and a domain for a specific chain/symbol.

The DeleteWeb3RecordTypes constant is defined as:

Example

3. Set Primary Name

Sets a domain as the primary name for a wallet address (reverse resolution).

The SetPrimaryNameTypes constant is defined as:

Example

4. Unset Primary Name

Removes the primary name association for a wallet address.

The UnsetPrimaryNameTypes constant is defined as:

Example

Complete Working Example

Here's a complete example that demonstrates all operations:

Important Notes

  • All signatures expire after the time specified in signatureExpiresAt (in milliseconds since epoch)

  • The wallet address is derived from the signature, ensuring that only the wallet owner can make changes

  • Store your API key and private key securely and never expose them in client-side code

  • All endpoints will respond with 200 with an empty body in case of success

Error Handling

The API returns appropriate HTTP status codes and JSON responses for errors:

  • 400 - Bad Request: Invalid parameters or signature

  • 401 - Unauthorized: Invalid API key

  • 403 - Forbidden: Signature expired or incorrect

  • 404 - Not Found: Domain or wallet not found

Last updated