> ## 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.

# getMaxShredInsertSlot

> Returns the highest slot that can be inserted into the shred database

## Parameters

This method does not take any parameters.

## Response

<ResponseField name="result" type="number">
  The highest slot that can be inserted into the shred database
</ResponseField>

## Code Examples

### Basic Request

```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": "getMaxShredInsertSlot"
}'
```

### Using web3.js

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

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

// Get max shred insert slot
const maxShredInsertSlot = await connection.getMaxShredInsertSlot();
console.log('Max shred insert slot:', maxShredInsertSlot);

// Check if a slot can be inserted
async function canInsertSlot(slot: number) {
  const maxShredInsertSlot = await connection.getMaxShredInsertSlot();
  return slot <= maxShredInsertSlot;
}

// Get insert range
async function getInsertRange() {
  const maxShredInsertSlot = await connection.getMaxShredInsertSlot();
  const firstAvailableBlock = await connection.getFirstAvailableBlock();
  
  return {
    startSlot: firstAvailableBlock,
    endSlot: maxShredInsertSlot,
    totalSlots: maxShredInsertSlot - firstAvailableBlock + 1
  };
}
```

## Notes

1. Returns the highest slot that can be inserted into the shred database
2. Used to determine the range of slots available for shred insertion
3. The response is immediate as it reads from the current state
4. Slots beyond this value cannot be inserted
5. This value can change as the node processes new slots

## Best Practices

1. Use this method to determine shred insertion availability
2. Cache results when appropriate to reduce RPC load
3. Consider the impact of slot processing
4. Monitor for changes in max shred insert slot
5. Use in conjunction with other slot-related methods

## Common Errors

| Code   | Message                      | Solution                                     |
| ------ | ---------------------------- | -------------------------------------------- |
| -32601 | Method not found             | Verify you're connected to a Solana RPC node |
| -32007 | Slot information unavailable | Node may be bootstrapping or syncing         |

## Use Cases

1. **Shred Insertion Planning**
   ```typescript theme={null}
   interface InsertPlan {
     startSlot: number;
     endSlot: number;
     totalSlots: number;
     availableSlots: number[];
     unavailableSlots: number[];
   }

   async function planShredInsertion(
     targetSlots: number[]
   ): Promise<InsertPlan> {
     const maxShredInsertSlot = await connection.getMaxShredInsertSlot();
     const firstAvailableBlock = await connection.getFirstAvailableBlock();
     
     const availableSlots = targetSlots.filter(
       slot => slot >= firstAvailableBlock && slot <= maxShredInsertSlot
     );
     
     const unavailableSlots = targetSlots.filter(
       slot => slot < firstAvailableBlock || slot > maxShredInsertSlot
     );
     
     return {
       startSlot: firstAvailableBlock,
       endSlot: maxShredInsertSlot,
       totalSlots: maxShredInsertSlot - firstAvailableBlock + 1,
       availableSlots,
       unavailableSlots
     };
   }
   ```

2. **Slot Processing Monitoring**
   ```typescript theme={null}
   interface ProcessingAlert {
     type: 'lag' | 'gap' | 'unavailable';
     message: string;
     slot: number;
     maxShredInsertSlot: number;
   }

   class ProcessingMonitor {
     private previousMaxSlot: number | null = null;
     
     async monitorProcessing(
       targetSlots: number[]
     ): Promise<ProcessingAlert[]> {
       const maxShredInsertSlot = await connection.getMaxShredInsertSlot();
       const alerts: ProcessingAlert[] = [];
       
       // Check for processing lag
       if (this.previousMaxSlot !== null) {
         const expectedProgress = this.previousMaxSlot + 1;
         if (maxShredInsertSlot < expectedProgress) {
           alerts.push({
             type: 'lag',
             message: `Processing lag detected: expected ${expectedProgress}, got ${maxShredInsertSlot}`,
             slot: maxShredInsertSlot,
             maxShredInsertSlot
           });
         }
       }
       
       // Check target slots availability
       for (const slot of targetSlots) {
         if (slot > maxShredInsertSlot) {
           alerts.push({
             type: 'unavailable',
             message: `Slot ${slot} is beyond max shred insert slot`,
             slot,
             maxShredInsertSlot
           });
         }
       }
       
       this.previousMaxSlot = maxShredInsertSlot;
       return alerts;
     }
   }
   ```

3. **Shred Database Management**
   ```typescript theme={null}
   interface ShredDatabaseMetrics {
     availableRange: {
       start: number;
       end: number;
       total: number;
     };
     processingRate: number;
     lag: number;
     metadata: {
       timestamp: number;
       maxShredInsertSlot: number;
     };
   }

   class ShredDatabaseManager {
     private previousMetrics: {
       timestamp: number;
       maxSlot: number;
     } | null = null;
     
     async getMetrics(): Promise<ShredDatabaseMetrics> {
       const maxShredInsertSlot = await connection.getMaxShredInsertSlot();
       const firstAvailableBlock = await connection.getFirstAvailableBlock();
       const currentTime = Date.now();
       
       let processingRate = 0;
       let lag = 0;
       
       if (this.previousMetrics !== null) {
         const timeDiff = (currentTime - this.previousMetrics.timestamp) / 1000; // seconds
         const slotDiff = maxShredInsertSlot - this.previousMetrics.maxSlot;
         processingRate = slotDiff / timeDiff;
         
         const currentSlot = await connection.getSlot();
         lag = currentSlot - maxShredInsertSlot;
       }
       
       this.previousMetrics = {
         timestamp: currentTime,
         maxSlot: maxShredInsertSlot
       };
       
       return {
         availableRange: {
           start: firstAvailableBlock,
           end: maxShredInsertSlot,
           total: maxShredInsertSlot - firstAvailableBlock + 1
         },
         processingRate,
         lag,
         metadata: {
           timestamp: currentTime,
           maxShredInsertSlot
         }
       };
     }
   }
   ```
