---
title: getFeeForMessage
description: >-
  Returns the lamports the cluster would charge to process a serialized message
  at the requested commitment.
url: /docs/rpc/http/getfeeformessage
type: reference
hideTableOfContents: true
---

Returns the lamports the cluster would charge to process a serialized message at
the requested commitment.

<Callout type="info" title="Source">
  [`get_fee_for_message`](https://github.com/anza-xyz/agave/blob/v3.1.8/rpc/src/rpc.rs#L4254)
</Callout>

<APIMethod>

```jsonc !!request curl
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getFeeForMessage",
  "params": [
    // !hover message
    "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA",
    // !hover(1:3) config
    {
      // !hover commitment
      "commitment": "processed"
    }
  ]
}
```

```ts !!request title="Kit"
import {
  createSolanaRpc,
  getBase64Encoder,
  type TransactionMessageBytesBase64
} from "@solana/kit";

const rpc_url = "https://api.devnet.solana.com";
const rpc = createSolanaRpc(rpc_url);

// !hover message
let message =
  "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA";

let fee = await rpc
  .getFeeForMessage(message as TransactionMessageBytesBase64)
  .send();

console.log(fee);
```

```ts !!request title="web3.js"
import { Connection, Message, clusterApiUrl } from "@solana/web3.js";

const connection = new Connection(clusterApiUrl("devnet"), "confirmed");

// !hover message
let b64Message =
  "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA";
let message = Message.from(Buffer.from(b64Message, "base64"));

let fee = await connection.getFeeForMessage(message);

console.log(fee);
```

```rs !!request title="Rust"
use anyhow::Result;
use base64::{Engine as _, engine::general_purpose};

use solana_client::nonblocking::rpc_client::RpcClient;
use solana_commitment_config::CommitmentConfig;
use solana_sdk::message::Message;

#[tokio::main]
async fn main() -> Result<()> {
    let client = RpcClient::new_with_commitment(
        String::from("https://api.devnet.solana.com"),
        CommitmentConfig::confirmed(),
    );

    // !hover message
    let base_64_message = "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA";
    let bytes = general_purpose::STANDARD.decode(base_64_message).unwrap();
    let message: Message = bincode::deserialize(&bytes).unwrap();

    let fee = client.get_fee_for_message(&message).await?;

    println!("{:#?}", fee);

    Ok(())
}
```

### !params

#### !! message

!type string  
!required

Base-64 encoded transaction message. Accepts both legacy and v0 (versioned)
message formats.

#### !! config

!type object

Configuration object.

##### !! commitment

!type string  
!values processed confirmed finalized  
!default finalized

Solana RPC uses the following commitment levels:

| Value       | Description                                                                                                                                                                                                                                                                |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `processed` | Return data from the highest slot this node has processed on the fork it currently considers best. This is the newest view, but it can still change if the cluster switches forks.                                                                                         |
| `confirmed` | Return data from the highest slot that at least two-thirds of active stake has directly voted to confirm. This is more stable than `processed`, but it is still a weaker guarantee than `finalized`.                                                                       |
| `finalized` | Return data from the highest slot that the cluster recognizes as finalized. In practice, this means the slot has reached maximum vote lockout in validators' vote towers and is recognized by at least two-thirds of active stake. This is the strongest commitment level. |

##### !! minContextSlot

!type number

The minimum slot that the request can be evaluated at.

```json title="Example"
{ "minContextSlot": 341197000 }
```

### !!result

```jsonc !response
{
  "jsonrpc": "2.0",
  // !hover(1:4) result
  "result": {
    // !hover context
    "context": { "apiVersion": "3.1.8", "slot": 5068 },
    // !hover value
    "value": 5000
  },
  "id": 1
}
```

!type object

RpcResponse object containing:

#### !! context

!type object

Slot and API version the node used to answer this request.

| Field        | Type     | Description                                                                     |
| ------------ | -------- | ------------------------------------------------------------------------------- |
| `slot`       | `u64`    | Slot at which the node evaluated this request.                                  |
| `apiVersion` | `string` | RPC API version reported by the node. This field may be omitted by older nodes. |

#### !! value

!type u64 | null

Fee for the supplied message at the referenced blockhash, in lamports. Returns
`null` if the blockhash is no longer valid.

</APIMethod>
