@lit-protocol/vincent-scaffold-sdk
Version:
Shared build configuration and utilities for Vincent abilities and policies
50 lines (49 loc) • 1.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.nativeSend = void 0;
const signTx_1 = require("../primitive/signTx");
const sendTx_1 = require("../primitive/sendTx");
const toEthAddress_1 = require("../../la-helpers/toEthAddress");
/**
* Handler function for sending native tokens on the network
* This function handles the preparation, signing, and sending of native token transactions
*
* @param provider - The network provider instance
* @param pkpPublicKey - The PKP public key for transaction signing
* @param pkpEthAddress - The ethereum address derived from PKP
* @param amount - Amount to send in ether (will be converted to wei)
* @param to - Optional recipient address, defaults to self if not provided
* @returns The transaction hash
*/
const nativeSend = async ({ provider, pkpPublicKey, amount, to, }) => {
const fromAddress = (0, toEthAddress_1.toEthAddress)(pkpPublicKey);
const recipientAddress = to;
// Get transaction parameters
const nonce = await provider.getTransactionCount(fromAddress);
const gasLimit = await provider.estimateGas({
from: fromAddress,
to: recipientAddress,
value: ethers.utils.parseEther(amount),
});
const gasPrice = await provider.getGasPrice();
const txAmount = ethers.utils.parseEther(amount);
// Prepare unsigned transaction
const unsignedTx = {
to: recipientAddress,
value: txAmount,
gasLimit: gasLimit,
gasPrice: gasPrice,
nonce: nonce,
chainId: (await provider.getNetwork()).chainId,
};
// Sign transaction
const signedTxSignature = await (0, signTx_1.signTx)({
sigName: "native-send-tx",
pkpPublicKey: pkpPublicKey,
tx: unsignedTx,
});
// Send transaction
const txHash = await (0, sendTx_1.sendTx)(provider, signedTxSignature);
return txHash;
};
exports.nativeSend = nativeSend;