@descent-protocol/sdk
Version:
A Typescript library for interacting with the Descent Protocol
47 lines (46 loc) • 1.45 kB
JavaScript
// src/libs/transactions.ts
var Transaction = class {
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) => {
const transaction = await this.descent.signer.provider?.getTransaction(transactionHash);
return transaction?.nonce;
};
/**
* Get transaction count.
*
* @param address Address to get transaction count for.
* @returns Transaction count for address
*/
getTransactionCount = async (address) => {
const transactionCount = await this.descent.signer.provider?.getTransactionCount(address);
return transactionCount;
};
};
export {
Transaction
};