getFeeForMessage RPC Method
Please note that this method is only available in solana-core v1.9 or newer. Please use getFees for solana-core v1.8
Parameters
message
string
REQUIRED
Loading...
object
object
Loading...
commitment
string
Loading...
maxSupportedTransactionVersion
number
Loading...
Returns
result
Loading...
context
Loading...
apiVersion
Loading...
slot
Loading...
value
Loading...
Request
curl https://docs-demo.solana-mainnet.quiknode.pro/ \
  -X POST \
  -H "Content-Type: application/json" \
  -d '
    {
      "id":1,
      "jsonrpc":"2.0",
      "method":"getFeeForMessage",
      "params":[
        "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA",
        {
          "commitment":"processed"
        }
      ]
    }
'require "uri"
require "json"
require "net/http"
url = URI("https://docs-demo.solana-mainnet.quiknode.pro/")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request.body = JSON.dump({
  "id": 1,
  "jsonrpc": "2.0",
  "method": "getFeeForMessage",
  "params": [
    "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA",
    {
      "commitment": "processed"
    }
  ]
})
response = https.request(request)
puts response.read_body
import { createSolanaRpc, GetFeeForMessageApi, Rpc, TransactionMessageBytesBase64 } from "@solana/kit";
async function getFeeForMessageExample() {
  const rpc: Rpc<GetFeeForMessageApi> = createSolanaRpc("https://docs-demo.solana-mainnet.quiknode.pro/");
  const message: TransactionMessageBytesBase64 = "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA" as TransactionMessageBytesBase64;
  try {
    const feeResult = await rpc.getFeeForMessage(message, { commitment: 'processed' }).send();
    console.log("Fee for message:", feeResult);
  } catch (error) {
    console.error("Error:", error);
  }
}
getFeeForMessageExample();const web3 = require("@solana/web3.js");
(async () => {
  const solana = new web3.Connection("https://docs-demo.solana-mainnet.quiknode.pro/");
  const YOUR_TRANSACTION = new Transaction();
  const YOUR_MESSAGE = YOUR_TRANSACTION.compileMessage();
  console.log(await solana.getFeeForMessage(YOUR_MESSAGE));
})();
from solana.rpc.api import Client
from solana.keypair import Keypair
from solana.system_program import TransferParams, transfer
from solana.transaction import Transaction
sender, receiver = Keypair.from_seed(bytes(PublicKey(1))), Keypair.from_seed(bytes(PublicKey(2)))
txn = Transaction().add(transfer(TransferParams(from_pubkey=sender.public_key, to_pubkey=receiver.public_key, lamports=1000)))
solana_client = Client("https://docs-demo.solana-mainnet.quiknode.pro/")
print(solana_client.get_fee_for_message(txn.compile_message()))use reqwest::header;
use reqwest::Client;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let mut headers = header::HeaderMap::new();
    headers.insert("Content-Type", "application/json".parse().unwrap());
    let client = Client::new();
    let json_data = r#"
    {
        "id": 1,
        "jsonrpc": "2.0",
        "method": "getFeeForMessage",
        "params": [
            "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA",
            {
                "commitment": "processed"
            }
        ]
    }
    "#;
    let response = client
        .post("https://docs-demo.solana-mainnet.quiknode.pro/")
        .headers(headers)
        .body(json_data)
        .send()
        .await?; 
    let body = response.text().await?;
    println!("{}", body);
    Ok(())
}
Response
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "apiVersion": "2.1.21",
      "slot": 335501818
    },
    "value": null
  },
  "id": 1
}Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free