UNPKG

@descent-protocol/sdk

Version:

A Typescript library for interacting with the Descent Protocol

67 lines (66 loc) 2.44 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var transactions_exports = {}; __export(transactions_exports, { Transaction: () => Transaction }); module.exports = __toCommonJS(transactions_exports); class Transaction { constructor(descent) { this.descent = descent; } /** * Send transaction and get transaction hash. */ send = async (transactionConfig, transactionCallbacks = {}) => { return new Promise(async (resolve, reject) => { try { const tx = await this.descent.signer.sendTransaction(transactionConfig); const hash = tx.hash; const receipt = await tx.provider.getTransactionReceipt(hash); const confirmations = await tx.confirmations(); resolve(tx); transactionCallbacks.onReceipt && transactionCallbacks.onReceipt(receipt); transactionCallbacks.onConfirmation && transactionCallbacks.onConfirmation(confirmations, receipt); } catch (error) { reject(error); } }); }; /** * Get transaction Nonce. * * @param transactionHash Transaction hash to get nonce. */ getNonce = async (transactionHash) => { var _a; const transaction = await ((_a = this.descent.signer.provider) == null ? void 0 : _a.getTransaction(transactionHash)); return transaction == null ? void 0 : transaction.nonce; }; /** * Get transaction count. * * @param address Address to get transaction count for. * @returns Transaction count for address */ getTransactionCount = async (address) => { var _a; const transactionCount = await ((_a = this.descent.signer.provider) == null ? void 0 : _a.getTransactionCount(address)); return transactionCount; }; }