GetFeeForMessage
Returns the fee estimate for a given message (transaction) payload.
Type: unary
Overview
GetFeeForMessage calculates the fee that would be charged for processing a given transaction message. This is useful for displaying fee estimates to users before they sign a transaction, and for optimizing priority fee calculations in competitive MEV environments.
The fee depends on the number of signatures required and any priority fees specified in compute budget instructions.
Parameters
| Name | Type | Description |
|---|---|---|
| message | bytes | Required. The serialized transaction message |
| commitment | CommitmentLevel | Optional. The commitment level |
Response
| Field | Type | Description |
|---|---|---|
| fee | uint64 | The estimated fee in lamports |
| slot | uint64 | The slot at which the estimate was calculated |
Usage Examples
Node.js
1const grpc = require('@grpc/grpc-js');
2const protoLoader = require('@grpc/proto-loader');
3
4const packageDef = protoLoader.loadSync('geyser.proto', {
5 keepCase: true, longs: String, enums: String, defaults: true, oneofs: true
6});
7const proto = grpc.loadPackageDefinition(packageDef).geyser;
8const client = new proto.Geyser('[IP_ADDRESS]:[PORT]', grpc.credentials.createInsecure());
9
10client.getFeeForMessage({}, (err, response) => {
11 if (err) { console.error(err); return; }
12 console.log('Response:', response);
13});Rust
1use yellowstone_grpc_proto::geyser::geyser_client::GeyserClient;
2use tonic::transport::Channel;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let channel = Channel::from_static("http://[IP_ADDRESS]:[PORT]")
7 .connect().await?;
8 let mut client = GeyserClient::new(channel);
9
10 let response = client.getFeeForMessage(tonic::Request::new(())).await?;
11 println!("Response: {:?}", response.into_inner());
12
13 Ok(())
14}