Parameters
The commitment level to use for the fee calculation
Response
The slot this request was processed in
Fee in lamports that will be charged for processing the message, or null if the message is invalid or the fee cannot be calculated
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
- Returns the fee the network will charge for a particular message
- Useful for calculating transaction fees more accurately
- Preferred over older fee calculation methods
- Different commitment levels can be specified
- Returns null if the message is invalid or can’t be processed
Best Practices
- Use this method for accurate fee prediction before sending transactions
- Provide a valid base64-encoded message to avoid null responses
- Handle null responses appropriately in your application
- Handle network errors and retry when appropriate
- Use this method when precise fee calculation is needed