Trustless Work
Spanish
Spanish
  • Bienvenido
  • Inicio
    • Guía rápida
    • Conceptos clave
    • Herramientas esenciales
  • ☀️Acerca de Trustless Work
    • Visión y Misión
    • 🛤️Nuestro Camino Hasta Ahora
      • 🤔El Problema: Orígen de Trustless Work
      • 👾El Equipo Se Une
      • 💡La Solución: Escrows
      • 🏆Hitos Clave
        • 🌠DraperU Stellar Astro Hacker House: Un Antes y Un Después
        • Lanzamiento de la API V1 en el Pura Vida ETH Hackathon
      • 🚀Programas Actuales
        • 🌟DraperU Embark Program
        • 💻OD Hack Campaigns
      • 🛠️Desarrollo Vertical
      • 🔮Visión a Futuro
    • Equipo
  • ⚒️Descripción de la Tecnología
    • 🚀Smart Escrow API
    • ⛓️Smart Contracts Open-Source de Escrow
    • 📂Plantillas Open-Source y Herramientas Para Desarrolladores
    • 💵USDC: La Stablecoin Detrás de Trustless Work
    • 🌟Stellar y Soroban: El Motor de Trustless Work
  • 🌍Casos de Uso: Escrow-as-a-Service Para Cualquier Industria
    • 🌎Proyecto Destacado: Kindfi
  • 🤖Tutorial de Trustless Work Dapp
    • Paso 1: Accediendo a la Trustless Work Dapp e Iniciando Sesión
    • Paso 2: Creación de Perfil y Solicitud de Clave API
    • Step 3: Crea un Escrow
    • Step 4: Financiando un Escrow
    • Paso 5: Marcando un Hito Como Completo ✅
    • Paso 6: Aprobando el Hito
    • Paso 7: Liberación del Pago
    • Cómo Obtener Testnet Tokens
  • 💻Recursos Para Desarrolladores
    • Smart Escrow Design
      • ¿Cómo Se Ve un Smart Escrow?
      • Roles En Trustless Work
    • Ciclo de Vida del Escrow
      • Fase de Iniciación
      • Fase de Financiamiento
      • Fase de Completamiento
      • Fase de Aprobación
      • Fase de Liberación
      • Resolución de Disputas
    • Referencia de API
      • Introducción
        • Cómo Integrarnos
      • Implementación (Deploy)
        • Inicia el escrow
      • Autenticación
        • Solicitar una Clave API
      • Escrows
        • Schema
        • Financiar Escrow
        • Obtener Escrow por Contract ID
        • Resolución de Disputas
        • Cambiar el Estado del Hito (Milestone)
        • Cambiar el Flag del Hito (Milestone)
        • Cambiar Flag de Disputa
        • Obtener el Balance de Múltiples Escrows
        • Distribuir Ganancias del Escrow
      • Helpers (Funciones Auxiliares)
        • Establecer Trustline
        • Enviar Transacción
    • Stellar Wallets
      • Freighter Wallet
      • Albedo Wallet
      • xBull Wallet
      • Rabet Wallet
      • Lobstr Wallet
      • Hana Wallet
      • Recursos adicionales
      • Solución de problemas y preguntas frecuentes
  • 🫂Comunidad y Roadmap
    • Comunidad
      • Notion para Startups
      • Meru
    • Involúcrate
    • 🛣️Roadmap: El Camino por Delante
  • 🎒Contexto Histórico
    • 📜Historia de los Escrows:
      • 🗿De la Era Antigua a la Colonial
      • 🏦La Era Bancaria (Siglo XIX - XX)
      • 💻La Era Digital y el Escrow en Línea
    • ⛓️La Era de la Blockchain: Smart Escrows
  • 📢Apéndices
    • Contacto y Soporte
    • Enlaces
      • ⚒️Trustless Work dApp
      • 🌐Trustless Work Website
      • 📣Telegram Chat
      • 💎Only Dust Profile
      • 👩‍💻Swagger for API
      • 📜Github
Powered by GitBook
LogoLogo

Links

  • Website
On this page

Was this helpful?

Export as PDF
  1. Recursos Para Desarrolladores
  2. Referencia de API
  3. Introducción

Cómo Integrarnos

Here you'll find the basic flow in order to use Trustless Work API. In this flows tutorial, we'll use as an example the integration of Trustless Work in our dApp.

PreviousIntroducciónNextImplementación (Deploy)

Last updated 1 month ago

Was this helpful?

Notas Importantes

Asegúrate de revisar la sección de para una asistencia visual.

  • Estamos usando la librería de Stellar Wallet Kit.

  • Estamos usando la librería de axios con una preconfiguración con la URL de Trustless Work y Bearer como token.

import axios from "axios";

const http = axios.create({
  baseURL: process.env.API_URL || "", // Trustless Work API URL
  timeout: 60000, // time
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${process.env.API_KEY}`, // Trustless Work API Key
  },
});

export default http;
  • Deberías conectar tu wallet favorita. Si te encuentras desarrollando, la recomendación es Freighter.

  • Podrás ver la entidad del escrow en la siguiente página.


Pasos

  1. Inicia el escrow

El contrato de escrow debe ser implementado, lo cual inicia el escrow con sus metadatos.

Payload Type:

export type EscrowPayload = Omit<
  Escrow,
  "user" | "createdAt" | "updatedAt" | "id"
>;

Ejecutar Endpoint:

interface EscrowPayloadWithSigner extends EscrowPayload {
  signer?: string;
}

export const initializeEscrow = async (
  payload: EscrowPayloadWithSigner,
) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Add the signer
    const payloadWithSigner: EscrowPayloadWithSigner = {
      ...payload,
      signer: address,
    };

    // Execute the endpoint
    const response = await http.post(
      "/deployer/invoke-deployer-contract",
      payloadWithSigner,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

    // Send the transaction to Stellar Network
    const tx = await http.post("/helper/send-transaction", {
      signedXdr: signedTxXdr,
      returnValueIsRequired: true,
    });

    const { data } = tx;

    return data;
  } catch (error: unknown) {
    // catch code ...
  }
};

Referencias:

  1. Financiar escrow

Cada escrow debe ser financiado antes de liberar fondos o resolver disputas. Es importante aclarar que puedes financias el escrow en cualquier momento, pero para este caso, lo financiaremos desde el principio.

Payload Type:

export type FundEscrowPayload = Pick<Escrow, "amount" | "contractId"> & {
  signer: string;
};

Ejecutar Endpoint:

export const fundEscrow = async (payload: FundEscrowPayload) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.post("/escrow/fund-escrow", payload);

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

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

    const { data } = tx;
    return data;
  } catch (error: unknown) {
    // catch code...
  }
};

Referencias:


These endpoints don't have any specific order to execute them

  1. Editar Hitos

Puedes editar los hitos en cualquier momento, pero sólo la entidad de la plataforma (platform entity) podrá hacerlo. Sólo los hitos pendientes serán editables.

Payload Type:

export type EditMilestonesPayload = {
  contractId: string;
  escrow: EscrowPayload;
  signer: string;
};

Ejecutar Endpoint:

export const editMilestones = async (payload: EditMilestonesPayload) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.put(
      "/escrow/update-escrow-by-contract-id",
      payload,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

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

    const { data } = tx;
    return data;
  } catch (error: unknown) {
    // catch code...
  }
};

Referencias:

ADD REFERENCES

  1. Cambiar el estado del hito

Con este endpoint podrás cambiar el estado de los hitos, pero sólo el proveedor de servicios (service provider) podrá hacerlo.

Payload Type:

export type ChangeMilestoneStatusPayload = {
  contractId?: string;
  milestoneIndex: string;
  newStatus: MilestoneStatus; // you can custom your status
  serviceProvider?: string;
};

Ejecutar Endpoint:

export const changeMilestoneStatus = async (
  payload: ChangeMilestoneStatusPayload,
) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.post(
      "/escrow/change-milestone-status",
      payload,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

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

    const { data } = tx;
    return data;
  } catch (error: unknown) {
   // catch code...
  }
};

Referencias:

  1. Cambiar flag del hito

Con este endpoint podrás aprobar los hitos, pero sólo el aprobador (approver) podrá hacerlo.

Payload Type:

export type ChangeMilestoneFlagPayload = Omit<
  ChangeMilestoneStatusPayload,
  "serviceProvider" | "newStatus"
> & {
  approver?: string;
  newFlag: boolean;
};

Ejecutar Endpoint:

export const changeMilestoneFlag = async (
  payload: ChangeMilestoneFlagPayload,
) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.post(
      "/escrow/change-milestone-flag",
      payload,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

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

    const { data } = tx;
    return data;
  } catch (error: unknown) {
   // catch code...
  }
};

Referencias:

  1. Cambiar flag de la disputa

En cualquier momento, el aprobador (approver) o proveedor de servicio (service provider) puede iniciar una disputa. Esto no puede ser ejecutado sin fondos en el balance del escrow.

Payload Type:

export type StartDisputePayload = Pick<Escrow, "contractId"> & {
  signer: string;
};

Ejecutar Endpoint:

export const startDispute = async (
  payload: StartDisputePayload,
) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.post(
      "/escrow/change-dispute-flag",
      payload,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

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

    const { data } = tx;
    return data;
  } catch (error: unknown) {
   // catch code...
  }
};

Referencias:


Caso #1: Si todos los hitos son completados y aprobados, podrás liberar los fondos.

  1. Distribuir ganancias del escrow

Cuando el escrow se encuentra listo para ser liberado, puedes hacerlo con este endpoint. Sólo el firmante de la liberación (release signer) puede hacerlo.

Payload Type:

export type DistributeEscrowEarningsEscrowPayload = Pick<Escrow, "contractId"> &
  Partial<Pick<Escrow, "serviceProvider" | "releaseSigner">> & {
    signer: string;
  };

Execute Endpoint:

export const distributeEscrowEarnings = async (
  payload: DistributeEscrowEarningsEscrowPayload,
) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.post(
      "/escrow/distribute-escrow-earnings",
      payload,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

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

    const { data } = tx;
    return data;
  } catch (error: unknown) {
   // catch code...
  }
};

Referencias:

Caso #2: Si el aprobador o proveedor de servicios iniciaron la disputa, tu podrás resolver la disputa.

  1. Resolver disputa

Cuando el escrow se encuentra en disputa, podrás resolverlo con este endpoint. Sólo el resolutor de disputas (dispute resolver) puede hacerlo.

Payload Type:

export type ResolveDisputePayload = Pick<Escrow, "contractId"> &
  Partial<Pick<Escrow, "disputeResolver">> & {
    approverFunds: string;
    serviceProviderFunds: string;
  };

Execute Endpoint:

export const resolveDispute = async (
  payload: ResolveDisputePayload,
) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.post(
      "/escrow/resolving-disputes",
      payload,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

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

    const { data } = tx;
    return data;
  } catch (error: unknown) {
   // catch code...
  }
};

Referencias:

Nota importante

Todos los endpoints relacionados con la gestión de escrows devuelven la transacción sin firmar. Esto se realiza mediante una cadena en formato XDR (External Data Representation), que es el formato que Stellar utiliza para codificar transacciones. Esta cadena XDR es la que debes usar para firmar la transacción con la billetera de tu elección. Una vez firmada, la transacción se devuelve firmada en el mismo formato, es decir, como un string en formato XDR.

  • Este string es el que debe ser enviado al siguiente endpoint para que la transacción sea enviado a la red de Stellar:

Eso es todo. Gracias.

💻
Stellar Wallets
Schema
Inicia el escrow
Fase de Iniciación
Financiar Escrow
Fase de Financiamiento
Fase de Completamiento
Cambiar el Estado del Hito (Milestone)
Fase de Aprobación
Cambiar el Flag del Hito (Milestone)
Cambiar Flag de Disputa
Fase de Liberación
Distribuir Ganancias del Escrow
Resolución de Disputas
Resolución de Disputas
Smart Escrow Design
Welcome! | Stellar Wallets Kit
Logo
https://dev.api.trustlesswork.com/helper/send-transactiondev.api.trustlesswork.com