TS/JS + Fetch
Learn how to submit a signed Cardano transaction 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/submit-tx.ts
import { API_URL, HEADERS } from "../utils/constant.ts";
const SIGNATURE =
"a1008182582085bd57924203d54f2b14bb3be31403807c9bc72e1d0e71541a2c76a931d851bf58404bfca09e2e9052cb9c7f0f1328d8586e648850043441ca2f6af2b03de8aaef1866d6ccc9ac7982a9f8222ba08e4c5bfcfa37af5c895cbf9955e7cca4f189310e";
const TRANSACTION =
"84a500d901028b82582001067f3a391f238c4f78c542e30a1f798063f53bbaba381a5af093d900e0a4ae008258200a9265df11e82f81ba7d66494cb00d3548e596a40124de0a2a58ab49a9bed6ea008258201c15378279cea85c6ae89c96114f70eafade5b854e9394f0fb422ca51fcd0d000082582038c976f25f78336a1f8867ba54e73b40fd292421dc7de9fdba6b7459935c0e7e008258204bda7eaf3f9b398120831785000bcc46023451085ba444632bd092bea77256a50082582051c1f536e3a4dd63147236aa7c82687ddc1cabe9a48168b6c2c42d89a906f537008258206166efb4a106e680e25b45fbbc35e31720b11347e9cb42e0a60d185e5e9822cd0082582063e999af49e95a215821e4a8ad520a7f887739d1571239688c8fd2db7e5fa441008258206b0df6e6a83f11b4c4ba7c7541d05781a348a00cf05f0385c634f3d9319adfda008258208690a52b09d32d68f8ad11c4967df5361c673f2ef492e0ceaf1456cc08ae7d4600825820ffb76b800f7bc7fcf0cbd91201cd1f16e05651615970ff99a0b5b193e85238440001818258390097d20ce7a3003369cf916bafb166fe94a4fcc6af61250abfe377122879773d7df44c3af7e3ad81b8be3cf76a5043a15ecf18e1d3d669d00d1a00989680021a000f4240031a0532409c081a0532247ca0f5f6";
const BODY = {
transaction: TRANSACTION,
signatures: [SIGNATURE],
};
const response = await fetch(`${API_URL}/transactions/submit`, {
method: "POST",
headers: HEADERS,
body: JSON.stringify(BODY),
});
console.log(await response.json());
Learn More
For a detailed overview of the transaction lifecycle, see the Transaction Guide.
Last updated
Was this helpful?