getFeeForMessage
Returns the fee that the network will charge for a particular message. The message must be base-64 encoded and is typically obtained from a constructed transaction. This is the recommended way to estimate transaction costs on Solana, replacing the deprecated getFeeCalculatorForBlockhash. It accounts for the number of signatures, compute budget instructions, and priority fees.
Parameters
| # | Type | Required | Description |
|---|---|---|---|
| 1 | string | Yes | Base-64 encoded serialized transaction message |
| 2 | object | No | Configuration object |
Configuration object fields:
| Field | Type | Description |
|---|---|---|
commitment | string | Commitment level: processed, confirmed, or finalized |
minContextSlot | number | Minimum slot at which the request can be evaluated |
Response
Returns an RpcResponse object:
| Field | Type | Description |
|---|---|---|
context.slot | u64 | The slot at which the fee was evaluated |
value | `u64 | null` |
Code Examples
cURL
1curl http://[IP_ADDRESS]:[PORT] -X POST -H "Content-Type: application/json" -d '{
2 "jsonrpc": "2.0",
3 "id": 1,
4 "method": "getFeeForMessage",
5 "params": [
6 "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA",
7 { "commitment": "confirmed" }
8 ]
9}'TypeScript
1const response = await fetch("http://[IP_ADDRESS]:[PORT]", {
2 method: "POST",
3 headers: { "Content-Type": "application/json" },
4 body: JSON.stringify({
5 jsonrpc: "2.0",
6 id: 1,
7 method: "getFeeForMessage",
8 params: [
9 "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA",
10 { commitment: "confirmed" }
11 ]
12 }),
13});
14const { result } = await response.json();
15console.log("Fee:", result.value, "lamports");Python
1import requests
2
3response = requests.post("http://[IP_ADDRESS]:[PORT]", json={
4 "jsonrpc": "2.0",
5 "id": 1,
6 "method": "getFeeForMessage",
7 "params": [
8 "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA",
9 {"commitment": "confirmed"}
10 ]
11})
12result = response.json()["result"]
13print(f"Fee: {result['value']} lamports")Rust
1use reqwest::Client;
2use serde_json::json;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let client = Client::new();
7 let res = client.post("http://[IP_ADDRESS]:[PORT]")
8 .json(&json!({
9 "jsonrpc": "2.0",
10 "id": 1,
11 "method": "getFeeForMessage",
12 "params": [
13 "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA",
14 {"commitment": "confirmed"}
15 ]
16 }))
17 .send().await?
18 .text().await?;
19 println!("{}", res);
20 Ok(())
21}Example Response
1{
2 "jsonrpc": "2.0",
3 "result": {
4 "context": { "slot": 123456789 },
5 "value": 5000
6 },
7 "id": 1
8}