Parameters

message
string
required

Base-64 encoded Message

commitment
string

The commitment level to use for the fee calculation

Response

result
object

Code Examples

Basic Request

curl http://rpc.orbitflare.com -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getFeeForMessage",
  "params": [
    "AQABAyRn/PA8jzJtN6oAyB3VR0nfOF0xnfkYaKwY4Ir3nrHFJGqhAQICAAEDAgABDAIAAAAEAAAAAAAA",
    {"commitment": "processed"}
  ]
}'

Using web3.js

import { Connection } from '@solana/web3.js';

const connection = new Connection('http://rpc.orbitflare.com');
const message = 'AQABAyRn/PA8jzJtN6oAyB3VR0nfOF0xnfkYaKwY4Ir3nrHFJGqhAQICAAEDAgABDAIAAAAEAAAAAAAA';
const fee = await connection.getFeeForMessage(message);
console.log(fee);

Using Python

from solana.rpc.api import Client

client = Client("http://rpc.orbitflare.com")
message = "AQABAyRn/PA8jzJtN6oAyB3VR0nfOF0xnfkYaKwY4Ir3nrHFJGqhAQICAAEDAgABDAIAAAAEAAAAAAAA"
response = client.get_fee_for_message(message)
print(response)

Notes

  1. Returns the fee the network will charge for a particular message
  2. Useful for calculating transaction fees more accurately
  3. Preferred over older fee calculation methods
  4. Different commitment levels can be specified
  5. Returns null if the message is invalid or can’t be processed

Best Practices

  1. Use this method for accurate fee prediction before sending transactions
  2. Provide a valid base64-encoded message to avoid null responses
  3. Handle null responses appropriately in your application
  4. Handle network errors and retry when appropriate
  5. Use this method when precise fee calculation is needed