Skip to content

Commit e763311

Browse files
committed
use broadcasthex for trx
1 parent b183373 commit e763311

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

src/server/handlers/private-api.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,42 @@ const fetchTronBalance = async (node: ChainstackNode, address: string): Promise<
687687
const broadcastTronTransaction = async (
688688
node: ChainstackNode,
689689
signedPayload: string,
690-
): Promise<ChainBroadcastResponse> => broadcastEvmTransaction("tron", node, signedPayload);
690+
): Promise<ChainBroadcastResponse> => {
691+
const endpoint = ensureHttpsEndpoint(node).replace(/\/+$/, "");
692+
const config = buildNodeAxiosConfig(node);
693+
694+
const normalizedPayload = signedPayload.startsWith("0x") ? signedPayload.slice(2) : signedPayload;
695+
696+
const payload = {
697+
transaction: normalizedPayload,
698+
};
699+
700+
const response = await axios.post(`${endpoint}/wallet/broadcasthex`, payload, config);
701+
const data = response.data;
702+
703+
if (data?.result === false) {
704+
const message = typeof data?.message === "string" ? data.message : undefined;
705+
let decodedMessage = message;
706+
707+
if (message) {
708+
try {
709+
decodedMessage = Buffer.from(message, "base64").toString("utf8");
710+
} catch (err) {
711+
decodedMessage = message;
712+
}
713+
}
714+
715+
throw new Error(decodedMessage || "Tron broadcast failed");
716+
}
717+
718+
return {
719+
chain: "tron",
720+
txId: data?.txid,
721+
raw: data,
722+
nodeId: node.id,
723+
provider: "chainstack",
724+
};
725+
};
691726

692727
const requestToncenterBalance = async (
693728
baseEndpoint: string,

0 commit comments

Comments
 (0)