UNPKG

@gear-js/api

Version:

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

50 lines (46 loc) 1.5 kB
'use strict'; var util = require('@polkadot/util'); var gear_errors = require('../errors/gear.errors.js'); class GearTransaction { _api; extrinsic; constructor(_api) { this._api = _api; } async signAndSend(account, optionsOrCallback, optionalCallback) { const [options, callback] = util.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 gear_errors.TransactionError('Account balance too low'); } else { throw new gear_errors.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); } } exports.GearTransaction = GearTransaction;