Enviar Transacción

La mayoría de los endpoints de Trustless Work devuelven una transacción no firmada en formato XDR. Este endpoint se utiliza para firmar dichas transacciones no firmadas y enviarlas a la red de Stellar

POST helper/send-transaction

Headers

Nombre
Valor

Content-Type

application/json

Authorization

Bearer <token>

Cuerpo

Nombre
Tipo
Descripción

signedXdr

string

El hash de la firma. Este proviene de la wallet.

returnEscrowDataIsRequired (Optional)

boolean

Si la data que retorna un escrow is necesaria (Nota que no todas las funciones de contrato retornan data de un escrow).

Ejemplo de cuerpo de solicitud (request body)

{
  "signedXdr": "AAAAAgAAAAB...",
  "returnValueIsRequired": true,
}

Respuestas posibles

{
    "status": "SUCCESS",
    "message": "The transaction has been successfully sent to the Stellar network"
}

Ejemplo de como usar este endpoint

import { FundEscrowPayload } from "@/@types/escrow.entity";
import { kit } from "@/components/modules/auth/wallet/constants/wallet-kit.constant";
import { WalletNetwork } from "@creit.tech/stellar-wallets-kit";
import { signTransaction } from "@stellar/freighter-api";
import axios from "axios";

const http = axios.create({
  baseURL: "https://dev.api.trustlesswork.com",
  timeout: 10000,
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer your_api_key`,
  },
});

export const fundEscrow = async () => {
  try {
    const response = await http.post(
      "/escrow/fund-escrow", 
      {
       // body requested for the endpoint
      }    
    );

    const { unsignedTransaction } = response.data;
    const { address } = await kit.getAddress();
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

    const tx = await http.post("/helper/send-transaction", {
      signedXdr: signedTxXdr,
    });

    const { data } = tx;
    return data;
  } catch (error: unknown) {
    if (axios.isAxiosError(error)) {
      console.error("Axios Error:", error.response?.data || error.message);
      throw new Error(
        error.response?.data?.message || "Error in Axios request",
      );
    } else {
      console.error("Unexpected Error:", error);
      throw new Error("Unexpected error occurred");
    }
  }
};

Last updated

Was this helpful?