> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orbitflare.com/llms.txt
> Use this file to discover all available pages before exploring further.

# getRecentBlockhash

> [DEPRECATED] Returns a recent blockhash and its fee schedule

# getRecentBlockhash

<Warning>
  This method is deprecated. Please use [`getLatestBlockhash`](/rpc/methods/getLatestBlockhash) instead, which provides more accurate and reliable blockhash information.
</Warning>

Returns a recent blockhash and its fee schedule. This method will be removed in a future release.

## Parameters

<ResponseField name="config" type="object" optional>
  <Expandable title="config fields">
    <ResponseField name="commitment" type="string" optional>
      Commitment level (processed, confirmed, finalized)
    </ResponseField>
  </Expandable>
</ResponseField>

## Response

<ResponseField name="result" type="object">
  <Expandable title="result fields">
    <ResponseField name="context" type="object">
      <ResponseField name="slot" type="number">
        Slot at which the request was processed
      </ResponseField>
    </ResponseField>

    <ResponseField name="value" type="object">
      <ResponseField name="blockhash" type="string">
        Recent blockhash (base-58 encoded)
      </ResponseField>

      <ResponseField name="feeCalculator" type="object">
        <ResponseField name="lamportsPerSignature" type="number">
          Fee in lamports per signature
        </ResponseField>
      </ResponseField>
    </ResponseField>
  </Expandable>
</ResponseField>

## Migration Guide

To migrate from `getRecentBlockhash` to `getLatestBlockhash`:

1. Replace method calls:

```diff theme={null}
- const { blockhash, feeCalculator } = await connection.getRecentBlockhash();
+ const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
```

2. Update fee calculations:

```typescript theme={null}
// Old way
const fee = feeCalculator.lamportsPerSignature * numSignatures;

// New way
const fee = await connection.getFeeForMessage(message);
```

## Code Examples

### Basic Request (Legacy)

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getRecentBlockhash",
  "params": []
}'
```

### Request with Commitment (Legacy)

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getRecentBlockhash",
  "params": [
    {
      "commitment": "confirmed"
    }
  ]
}'
```

### Using web3.js (Legacy)

```typescript theme={null}
import { Connection } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');

// Get recent blockhash (deprecated)
const { value: { blockhash, feeCalculator } } = await connection.getRecentBlockhash();
console.log('Blockhash:', blockhash);
console.log('Fee per signature:', feeCalculator.lamportsPerSignature);
```

## Notes

1. This method is deprecated and will be removed in a future release
2. Use `getLatestBlockhash` for new development
3. The blockhash is valid for a limited time (typically 150 slots)
4. Different commitment levels can be specified
5. Consider updating existing code to use the new methods

## Best Practices

1. Migrate to `getLatestBlockhash` for new development
2. Use `getFeeForMessage` for fee calculations
3. Monitor for blockhash expiration using `lastValidBlockHeight`
4. Handle network errors and retry when appropriate
5. Use appropriate commitment level based on your needs

## Common Errors

| Code   | Message                           | Solution                                     |
| ------ | --------------------------------- | -------------------------------------------- |
| -32601 | Method not found                  | Verify you're connected to a Solana RPC node |
| -32602 | Invalid params                    | Check config parameters                      |
| -32007 | Blockhash information unavailable | Node may be bootstrapping or syncing         |

## Use Cases

1. **Transaction Fee Calculation**
   ```typescript theme={null}
   interface TransactionFee {
     blockhash: string;
     feePerSignature: number;
     totalFee: number;
     metadata: {
       timestamp: number;
       slot: number;
     };
   }

   async function calculateTransactionFees(
     numSignatures: number
   ): Promise<TransactionFee> {
     const { context, value } = await connection.getRecentBlockhash();
     
     return {
       blockhash: value.blockhash,
       feePerSignature: value.feeCalculator.lamportsPerSignature,
       totalFee: numSignatures * value.feeCalculator.lamportsPerSignature,
       metadata: {
         timestamp: Date.now(),
         slot: context.slot
       }
     };
   }
   ```

2. **Blockhash Monitoring**
   ```typescript theme={null}
   interface BlockhashInfo {
     blockhash: string;
     slot: number;
     feePerSignature: number;
     metadata: {
       timestamp: number;
       age: number;
     };
   }

   class BlockhashMonitor {
     private currentBlockhash: string | null = null;
     private currentSlot: number | null = null;
     
     async monitorBlockhash(
       interval: number = 5000
     ): Promise<BlockhashInfo | null> {
       const { context, value } = await connection.getRecentBlockhash();
       
       if (this.currentBlockhash === value.blockhash) {
         return null;
       }
       
       this.currentBlockhash = value.blockhash;
       this.currentSlot = context.slot;
       
       return {
         blockhash: value.blockhash,
         slot: context.slot,
         feePerSignature: value.feeCalculator.lamportsPerSignature,
         metadata: {
           timestamp: Date.now(),
           age: 0
         }
       };
     }
   }
   ```

3. **Transaction Planning**
   ```typescript theme={null}
   interface TransactionPlan {
     blockhash: string;
     feePerSignature: number;
     estimatedFees: {
       single: number;
       batch: number;
     };
     metadata: {
       timestamp: number;
       slot: number;
     };
   }

   async function planTransactions(
     numTransactions: number,
     signaturesPerTransaction: number
   ): Promise<TransactionPlan> {
     const { context, value } = await connection.getRecentBlockhash();
     const feePerSignature = value.feeCalculator.lamportsPerSignature;
     
     return {
       blockhash: value.blockhash,
       feePerSignature,
       estimatedFees: {
         single: signaturesPerTransaction * feePerSignature,
         batch: numTransactions * signaturesPerTransaction * feePerSignature
       },
       metadata: {
         timestamp: Date.now(),
         slot: context.slot
       }
     };
   }
   ```
