DRep (TS/JS + Fetch)
Learn how to delegate to a DRep using TypeScript or JavaScript and the Anvil API.
https://github.com/Cardano-Forge/anvil-api-examples/blob/main/utils/constant.ts
// See Authentication page for API key details.
export const X_API_KEY = "testnet_EyrkvCWDZqjkfLSe1pxaF0hXxUcByHEhHuXIBjt9";
export const NETWORK = "preprod";
export const API_URL = `https://${NETWORK}.api.ada-anvil.app/v2/services`;
export const HEADERS = {
"Content-Type": "application/json",
"x-api-key": X_API_KEY,
};
https://github.com/Cardano-Forge/anvil-api-examples/blob/main/documentation-references/delegate-drep.ts
import { API_URL, HEADERS } from "../utils/constant.ts";
const DREP_ID = "drep13d6sxkyz6st9h65qqrzd8ukpywhr8swe9f6357qntgjqye0gttd";
const ADDR =
"addr_test1qq7fc3ke49nkcsfglltut7apa9t3gdul4utwhxt6j2hdrw7pg4vk6erdshyhdj5xeq0vh8qdy34cpdfstvc8l9su8hgq679eew";
const BODY = {
changeAddress: ADDR,
delegations: [
{
type: "drep",
address: ADDR,
keyHash: DREP_ID,
},
],
};
const response = await fetch(`${API_URL}/transactions/build`, {
method: "POST",
headers: HEADERS,
body: JSON.stringify(BODY),
});
console.log(await response.json());
// Expected outputs:
// {
// hash: "bbc624e784afd3183be5d4800652b963d5da7fbff6aab04a84b49d24949528c9",
// complete: "84a700d90102818258206a6bb5dafa917de09a2b727d4050c785f59f39f1b819e43a34570c8a5377cadf000181825839003c9c46d9a9676c4128ffd7c5fba1e95714379faf16eb997a92aed1bbc145596d646d85c976ca86c81ecb9c0d246b80b5305b307f961c3dd0821a1d3098c6a1581c360fd38656e5204f22ec058d18d5a90c18745ca8325e51d077c38a13a3581b616e76696c61706963697032355f3137343130333330373738303401581b616e76696c61706963697032355f3137343130333331383531353001581b616e76696c61706963697032355f3137343133363330393135333801021a00030f39031a0524c91d04d901028183098200581cc145596d646d85c976ca86c81ecb9c0d246b80b5305b307f961c3dd08200581c8b75035882d4165bea8000c4d3f2c123ae33c1d92a751a78135a2402081a0524acfd0ed9010281581cc145596d646d85c976ca86c81ecb9c0d246b80b5305b307f961c3dd0a0f5f6",
// stripped: "84a700d90102818258206a6bb5dafa917de09a2b727d4050c785f59f39f1b819e43a34570c8a5377cadf000181825839003c9c46d9a9676c4128ffd7c5fba1e95714379faf16eb997a92aed1bbc145596d646d85c976ca86c81ecb9c0d246b80b5305b307f961c3dd0821a1d3098c6a1581c360fd38656e5204f22ec058d18d5a90c18745ca8325e51d077c38a13a3581b616e76696c61706963697032355f3137343130333330373738303401581b616e76696c61706963697032355f3137343130333331383531353001581b616e76696c61706963697032355f3137343133363330393135333801021a00030f39031a0524c91d04d901028183098200581cc145596d646d85c976ca86c81ecb9c0d246b80b5305b307f961c3dd08200581c8b75035882d4165bea8000c4d3f2c123ae33c1d92a751a78135a2402081a0524acfd0ed9010281581cc145596d646d85c976ca86c81ecb9c0d246b80b5305b307f961c3dd0a0f5f6",
// witnessSet: "a0"
// }
Learn More
For a step-by-step explanation, see the Delegate to a DRep Guide.
Last updated
Was this helpful?