# getFeeForMessage

> Returns the fee, in lamports, that a compiled transaction message would cost right now.

Source: https://docs.constant-k.com/rpc/http/getfeeformessage/

`getFeeForMessage` takes a base64-encoded, compiled transaction `Message` (not a full transaction; no signatures required) and returns its fee under the current fee schedule, based on its signature count and compute-budget instructions.

The result depends on the message's embedded blockhash remaining recent, detailed further in Notes.

- Transport: HTTP, JSON-RPC 2.0 `POST` to `https://rpc-newyork.constant-k.com/?api-key=YOUR_API_KEY` (New York) or `https://rpc-frankfurt.constant-k.com/?api-key=YOUR_API_KEY` (Frankfurt) or `https://rpc-amsterdam.constant-k.com/?api-key=YOUR_API_KEY` (Amsterdam). The key also works as an `x-api-key` header.
- Category: Fees & Blockhash
- Availability: All plans
- Rate limits: Free 5/s · Operator 50/s · Blade Runner 200/s · Nexus 500/s

## Parameters

`params` is a positional JSON array, in this order:

- `message` (string, required): Base64-encoded, compiled transaction message (the `Message`, not a full signed `Transaction`).
- `config` (object, optional): Optional configuration.
  - `commitment` (string, optional, one of `finalized`, `confirmed`, `processed`, default `"finalized"`): Bank state to compute the fee against.
  - `minContextSlot` (integer, optional): Minimum slot the node must have processed before answering.

## Result

- `result` (object, optional): The fee in lamports, wrapped with context, or null if the fee can't be computed.
  - `context` (object, required)
    - `slot` (integer, optional)
    - `apiVersion` (string, optional)
  - `value` (integer | null, required): Fee in lamports for the given message, or null if the message's blockhash is not found (for example because it has already expired).

## Example: Get the fee for a simple transfer message

Request:

```bash
curl "https://rpc-newyork.constant-k.com/?api-key=YOUR_API_KEY" \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getFeeForMessage",
    "params": [
      "AQABAwECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALHv94dOt1UDOn1l55osLmbKjs32ODjR/8FyngXF0waaAQICAAEMAgAAAPQBAAAAAAAA"
    ]
  }'
```

Response:

```json
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "apiVersion": "4.3.0-rc.0",
      "slot": 447947974
    },
    "value": 5000
  },
  "id": 1
}
```

## Example: Message built on an expired blockhash

Request:

```bash
curl "https://rpc-newyork.constant-k.com/?api-key=YOUR_API_KEY" \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getFeeForMessage",
    "params": [
      "AQABAwECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJ/hQt7J5JXCmguACONf1lzqqm0DGt0NkqVxLgH/m/ixAQICAAEMAgAAAEBCDwAAAAAA"
    ]
  }'
```

Response:

```json
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "apiVersion": "4.3.0-rc.0",
      "slot": 447947764
    },
    "value": null
  },
  "id": 1
}
```

## Notes

- `value` is null when the embedded blockhash is too old for the node to have a fee schedule for it; this is not an error.
- 5000 lamports per signature is the current base fee; a priority fee from compute-budget instructions adds to it, and this call reflects that.
- Both example messages encode a single-signer SystemProgram transfer; they differ only in which blockhash was compiled into them.

