import { Call, Account } from 'starknet';
/**
* V3 transaction execution arguments
* @property {Call} call
* @property {Account} account
*/
export interface ExecuteV3Args {
call: Call;
account: Account;
}
/**
* Creates a V3 transaction details payload with predefined gas parameters
* @returns {Object} V3 transaction details payload with gas parameters
*/
export const getV3DetailsPayload = () => {
return {
version: 3,
maxFee: 10n ** 16n,
};
};
/**
* Executes a V3 transaction with preconfigured gas parameters
* @param {ExecuteV3Args} args - Contains call and account
* @returns {Promise<string>} Transaction hash
* @throws {Error} If transaction fails
*/
export const executeV3Transaction = async ({
call,
account,
}: ExecuteV3Args): Promise<string> => {
const { transaction_hash } = await account.execute(
call,
getV3DetailsPayload()
);
const receipt = await account.waitForTransaction(transaction_hash);
if (!receipt.isSuccess()) {
throw new Error('Transaction confirmed but failed');
}
return transaction_hash;
};