getFeeForMessage

How to Use It

// yarn add @tatumio/tatum

import { TatumSDK, Solana, Network } from '@tatumio/tatum'

const tatum = await TatumSDK.init<Solana>({ network: Network.SOLANA })

const message = {
  // Message content goes here...
}
const res = await tatum.rpc.getFeeForMessage(message)

await tatum.destroy() // Destroy Tatum SDK - needed for stopping background jobs

Overview

The getFeeForMessage method is used to estimate the transaction fee for a given message. This is very useful when you are preparing to send a transaction and you want to estimate the transaction cost. This can be used in situations where you need to validate whether a user has enough funds to cover the transaction fee or to provide an estimate of the cost to the user.

Parameters

  • message(string, required): Base-64 encoded Message for which the fee should be estimated.

    • Example: "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA"

  • options (object, optional): Configuration object containing the following fields:

    • commitment (string, optional): Specifies the confirmation level of data to be fetched.

      • Values: finalized confirmed processed

    • minContextSlot (number, optional): The minimum slot that the request can be evaluated at

      • Example: 1000

Return Object

The result will be a JSON object with value equal to Fee corresponding to the message at the specified blockhash

JSON-RPC Request Example

{
  "id":1,
  "jsonrpc":"2.0",
  "method":"getFeeForMessage",
  "params":[
    "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA",
    {
      "commitment":"processed"
    }
  ]
}

JSON-RPC Response Example

{
  "jsonrpc": "2.0",
  "result": { "context": { "slot": 5068 }, "value": 5000 },
  "id": 1
}

Last updated

ยฉ Tatum Technology, LLC