Enviar transacción
La mayoría de los endpoints de Trustless Work devuelven una transacción sin firmar en formato XDR. Este endpoint se usa para firmar dichas transacciones sin firmar y enviarlas a la red Stellar.
Encabezados
Nombre
Valor
Content-Type
application/json
x-api-key
<token>
Open API
post
Autorizaciones
Cuerpo
signedXdrstringRequeridoExample:
The sign's hash. This come from the wallet
AAAAAgAAAAB...Respuestas
200
The transaction has been successfully sent to the Stellar network
application/json
400
Bad request
401
Unauthorized access
429
Too Many Requests
500Error
application/json
post
/helper/send-transactionPOST /helper/send-transaction HTTP/1.1
Host:
Content-Type: application/json
Accept: */*
Content-Length: 30
{
"signedXdr": "AAAAAgAAAAB..."
}{
"status": "SUCCESS",
"message": "The transaction has been successfully sent to the Stellar network.",
"contractId": "CAATN5D...",
"escrow": {
"amount": 50,
"roles": {
"approver": "GAWVVSA...",
"serviceProvider": "GAWVVSA6...",
"disputeResolver": "GAWVVSA...",
"receiver": "GAWVVSA...",
"platformAddress": "GAWVVSA...",
"releaseSigner": "GAWVVSA..."
},
"flags": {
"disputed": false,
"released": false,
"resolved": false
},
"description": "This is a sample TW escrow for testing purposes",
"engagementId": "ENG12345",
"milestones": [
{
"approved": false,
"description": "Initial milestone",
"evidence": "",
"status": "pending"
},
{
"approved": false,
"description": "Second milestone",
"evidence": "",
"status": "pending"
}
],
"platformFee": 5,
"title": "Sample TW Escrow",
"trustline": {
"address": "CBIELTK...",
"name": "USDC"
},
"receiverMemo": 90909090
}
}Ejemplo de uso:
import axios from "axios";
const http = axios.create({
baseURL: "https://dev.api.trustlesswork.com",
timeout: 10000,
headers: {
"Content-Type": "application/json",
"x-api-key": tu_api_key,
},
});
export const useExample = async () => {
// Obtener la dirección del firmante
const { address } = await kit.getAddress();
const response = await http.post(
"/cualquier-endpoint",
{
// body solicitado para el endpoint
},
);
// Obtener el hash de la transacción sin firmar
const { unsignedTransaction } = response.data;
// Firmar la transacción con la cartera
const { signedTxXdr } = await signTransaction(unsignedTransaction, {
address,
networkPassphrase: WalletNetwork.TESTNET,
});
// Enviar la transacción a la Red Stellar <--------------- ESTO
const tx = await http.post("/helper/send-transaction", {
signedXdr: signedTxXdr,
});
const { data } = tx;
return data;
}Última actualización
¿Te fue útil?