UNPKG

@blockbolt/monad-wallet

Version:
86 lines 3.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BlockBolt = void 0; const viem_1 = require("viem"); const chain_1 = require("./constants/chain"); const validation_1 = require("./utils/validation"); const errors_1 = require("./utils/errors"); const blockboltABI_1 = require("./constants/abi/blockboltABI"); class BlockBolt { /** * Initialize the BlockBolt * @param contractAddress - The address of the payment contract */ constructor() { this.contractAddress = chain_1.BlockBolt_TESTNET_CONTRACT_ADDRESS; // Initialize clients this.publicClient = (0, viem_1.createPublicClient)({ chain: chain_1.MONAD_TESTNET, transport: (0, viem_1.http)(), }); this.walletClient = (0, viem_1.createWalletClient)({ chain: chain_1.MONAD_TESTNET, transport: (0, viem_1.http)(), }); } /** * Make a payment using the Monad contract * @param account - The account that will sign the transaction * @param paymentDetails - Details of the payment to be made * @returns Transaction hash */ async makePayment(account, paymentDetails) { // Validate payment details (0, validation_1.validatePaymentDetails)(paymentDetails); try { const { orderId, amount, merchantName, merchantAddress } = paymentDetails; const value = (0, viem_1.parseEther)(amount); // Simulate the transaction first const { request } = await this.publicClient.simulateContract({ account, address: this.contractAddress, abi: blockboltABI_1.BLOCKBOLT_MONAD_ABI, functionName: "transfer", args: [orderId.trim(), merchantName, merchantAddress], value, }); // Send the transaction const hash = await this.walletClient.writeContract(request); return { hash, }; } catch (error) { throw new errors_1.TransactionError(error.message || "Unknown error during payment"); } } /** * Get the transaction status * @param hash - Transaction hash to check */ async getTransactionStatus(hash) { try { const receipt = await this.publicClient.waitForTransactionReceipt({ hash, }); return { status: receipt.status, blockNumber: receipt.blockNumber, logs: receipt.logs, receipt, }; } catch (error) { throw new errors_1.TransactionError(`Failed to get transaction status: ${error.message}`); } } /** * Get the explorer URL for a transaction * @param hash - Transaction hash */ getExplorerUrl(hash) { return `${chain_1.MONAD_TESTNET.blockExplorers.default.url}/tx/${hash}`; } } exports.BlockBolt = BlockBolt; //# sourceMappingURL=blockbolt.js.map