UNPKG

@gear-js/api

Version:

A JavaScript library that provides functionality to connect GEAR Component APIs.

48 lines (45 loc) 1.45 kB
import { isFunction } from '@polkadot/util'; import { TransactionError } from '../errors/gear.errors.js'; class GearTransaction { _api; extrinsic; constructor(_api) { this._api = _api; } async signAndSend(account, optionsOrCallback, optionalCallback) { const [options, callback] = isFunction(optionsOrCallback) ? [undefined, optionsOrCallback] : [optionsOrCallback, optionalCallback]; try { return await this.extrinsic.signAndSend(account, options, callback); } catch (error) { console.log(error); const errorCode = +error.message.split(':')[0]; if (errorCode === 1010) { throw new TransactionError('Account balance too low'); } else { throw new TransactionError(error.message); } } } /** * * @param account * @param options * @example * ```javascript * const api = await GearApi.create(); * api.program.submit({code, gasLimit}); * // same for api.message, api.reply and others * const paymentInfo = await api.program.paymentInfo(alice); * const transactionFee = paymentInfo.partialFee.toNumber(); * consolg.log(transactionFee); * ``` */ paymentInfo(account, options) { return this.extrinsic.paymentInfo(account, options); } } export { GearTransaction };