How it works

How a DRep name is reserved, and how to resolve a name back to a DRep id from the chain, with a runnable example.


The DRep.ID standard lets a DRep reserve a name for themselves. The reserved name then resolves to that DRep's id, which is what makes them findable — and delegable — without anyone copying a bech32 string around.

Reserving a name

A reservation requires three things:

  • The DRep's off-chain signature
  • The platform's signature
  • A small registration fee

Resolving a name to a DRep id

Two steps, both against the chain:

  1. Find the address holding the token with that name.
  2. Extract the DRep id from the credential of the address holding it.

A worked example

This resolves a handle to its DRep id using Blockfrost and libcardano:

const libcardano = require('libcardano');
const axios = require('axios');

const handleName = 'spannercode';
const drepIdPolicy = '1bc9af6f44cee790f8d4ea19d8628213704cdb0ae54920f1f7715522';
const assetName = Buffer.from(handleName).toString('hex');

// Your own Blockfrost project id.
const API_KEY = '<your-blockfrost-project-id>';
const blockfrostUrl = 'https://cardano-mainnet.blockfrost.io';

const getDRepIdForHandle = async (policyId, assetNameHex) => {
  const apiClient = axios.create({
    baseURL: blockfrostUrl,
    headers: { project_id: API_KEY },
  });

  // Whoever holds the asset owns the handle.
  const { data } = await apiClient.get(
    `/api/v0/assets/${policyId}${assetNameHex}/addresses`
  );

  const [{ address }] = data;
  const addr = libcardano.ShelleyAddress.fromBech32(address);
  const stakePart = addr.stakePart;
  const drepCredential = new libcardano.DrepCredential(
    stakePart.bytes,
    stakePart.isScript
  );

  console.log('DRep key hash: ' + drepCredential.bytes.toString('hex'));
  console.log('DRep id:       ' + drepCredential.toBech32());
};

getDRepIdForHandle(drepIdPolicy, assetName);