diff --git a/packages/massa-web3/src/interfaces/INodeStatus.ts b/packages/massa-web3/src/interfaces/INodeStatus.ts index 031d93f8..a76d7f09 100644 --- a/packages/massa-web3/src/interfaces/INodeStatus.ts +++ b/packages/massa-web3/src/interfaces/INodeStatus.ts @@ -71,4 +71,5 @@ export interface INodeStatus { pool_stats: { endorsement_count: number; operation_count: number } version: string chain_id: bigint + minimal_fees?: string } diff --git a/packages/massa-web3/src/interfaces/IPublicApiClient.ts b/packages/massa-web3/src/interfaces/IPublicApiClient.ts index 8eb7452b..2af9b974 100644 --- a/packages/massa-web3/src/interfaces/IPublicApiClient.ts +++ b/packages/massa-web3/src/interfaces/IPublicApiClient.ts @@ -115,4 +115,11 @@ export interface IPublicApiClient extends BaseClient { getGraphInterval( graphInterval: IGetGraphInterval ): Promise> + + /** + * Get the minimal fees required for your operation to be accepted by the API provider + * + * @returns The minimal fees as bigint (in nano-MAS). + */ + getMinimalFees(): Promise } diff --git a/packages/massa-web3/src/web3/PublicApiClient.ts b/packages/massa-web3/src/web3/PublicApiClient.ts index 9d81e243..afa2320a 100755 --- a/packages/massa-web3/src/web3/PublicApiClient.ts +++ b/packages/massa-web3/src/web3/PublicApiClient.ts @@ -15,7 +15,7 @@ import { IDatastoreEntryInput } from '../interfaces/IDatastoreEntryInput' import { IGetGraphInterval } from '../interfaces/IGetGraphInterval' import { IGraphInterval } from '../interfaces/IGraphInterval' import { IBlockcliqueBlockBySlot } from '../interfaces/IBlockcliqueBlockBySlot' -import { ISlot } from '@massalabs/web3-utils' +import { ISlot, fromMAS } from '@massalabs/web3-utils' /** * Public API client for interacting with a Massa node. @@ -41,6 +41,7 @@ export class PublicApiClient extends BaseClient implements IPublicApiClient { // public api methods this.getNodeStatus = this.getNodeStatus.bind(this) + this.getMinimalFees = this.getMinimalFees.bind(this) this.getAddresses = this.getAddresses.bind(this) this.getBlocks = this.getBlocks.bind(this) this.getEndorsements = this.getEndorsements.bind(this) @@ -130,6 +131,30 @@ export class PublicApiClient extends BaseClient implements IPublicApiClient { return { ...nodeStatus, chain_id: BigInt(nodeStatus.chain_id) } } + /** + * Retrieves the minimal fees for operations to be accepted by the API provider. + * + * @returns The minimal fees as a bigint (in nano-MAS). + */ + public async getMinimalFees(): Promise { + const jsonRpcRequestMethod = JSON_RPC_REQUEST_METHOD.GET_STATUS + let fees: string = '0' + if (this.clientConfig.retryStrategyOn) { + let result = await trySafeExecute(this.sendJsonRPCRequest, [ + jsonRpcRequestMethod, + [], + ]) + fees = result.minimal_fees || '0' + } else { + let result = await this.sendJsonRPCRequest( + jsonRpcRequestMethod, + [] + ) + fees = result.minimal_fees || '0' + } + return fromMAS(fees) + } + /** * Retrieves data about a list of addresses, such as their balances and block creation details. *