UNPKG

@lit-protocol/vincent-scaffold-sdk

Version:

Shared build configuration and utilities for Vincent abilities and policies

32 lines (31 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendTx = void 0; /** * Broadcasts a signed transaction to the network. * @param {string} signedTx - The signed transaction. * @returns {Promise<string>} The transaction hash. */ const sendTx = async (provider, signedTx) => { console.log("Broadcasting transaction..."); const responseText = await Lit.Actions.runOnce({ waitForResponse: true, name: "txnSender" }, async () => { try { const receipt = await provider.sendTransaction(signedTx); console.log("Transaction sent:", receipt.hash); return receipt.hash; } catch (error) { console.error("Error broadcasting transaction:", error); return JSON.stringify(error); } }); if (responseText.includes("error")) { throw new Error(responseText); } const txHash = responseText; if (!ethers.utils.isHexString(txHash)) { throw new Error(`Invalid transaction hash: ${txHash}`); } return txHash; }; exports.sendTx = sendTx;