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

# Cách sử dụng getStakeMinimumDelegation

> Tìm hiểu các trường hợp sử dụng getStakeMinimumDelegation, ví dụ mã, tham số yêu cầu, cấu trúc phản hồi và mẹo.

Phương thức RPC [`getStakeMinimumDelegation`](https://www.helius.dev/docs/api-reference/rpc/http/getstakeminimumdelegation) trả về số lamport tối thiểu hiện tại cần thiết để tạo một ủy quyền [stake](https://www.helius.dev/blog/how-to-stake-solana) mới trên mạng Solana. Giá trị này có thể thay đổi theo thời gian do cơ chế quản trị hoặc các bản cập nhật của mạng.

## Các trường hợp sử dụng phổ biến

* **Xác thực số lượng stake:** Trước khi tạo tài khoản stake mới hoặc ủy quyền stake, hãy kiểm tra giá trị này để đảm bảo số lượng dự định ủy quyền đáp ứng yêu cầu tối thiểu.
* **UI/UX staking:** Hiển thị số lượng ủy quyền tối thiểu cho người dùng trong giao diện staking để hướng dẫn họ nhập dữ liệu.
* **Tập lệnh staking tự động:** Đảm bảo các quy trình staking tự động sử dụng số lượng ủy quyền hợp lệ.

## Tham số yêu cầu

Phương thức này có một tham số tùy chọn:

1. **`config`** (đối tượng, tùy chọn): Đối tượng cấu hình chứa trường sau:
   * **`commitment`** (chuỗi, tùy chọn): Chỉ định [mức cam kết](https://www.helius.dev/blog/solana-commitment-levels) sẽ sử dụng khi truy vấn giá trị. Nếu bỏ qua, mức cam kết mặc định của nút RPC sẽ được sử dụng (thường là `finalized`).

## Cấu trúc phản hồi

Trường `result` trong phản hồi JSON-RPC là một đối tượng `RpcResponse` chứa:

* **`context`** (đối tượng): Một đối tượng `RpcResponseContext` có trường sau:
  * **`slot`** (`u64`): Slot tại thời điểm dữ liệu được truy xuất.
* **`value`** (`u64`): Số lượng ủy quyền stake tối thiểu tính bằng lamport.

**Ví dụ về phản hồi:**

```json theme={"system"}
{
  "jsonrpc": "2.0",
  "result": {
    "context": { "slot": 123456789 },
    "value": 1000000000 // Represents 1 SOL, for example
  },
  "id": 1
}
```

## Ví dụ

### 1. Lấy số lượng ủy quyền stake tối thiểu hiện tại

Ví dụ này truy xuất số lượng ủy quyền stake tối thiểu hiện tại bằng mức cam kết mặc định.

<CodeGroup>
  ```bash cURL theme={"system"}
  # Replace <api-key> with your Helius API key
  curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getStakeMinimumDelegation"
    }'
  ```

  ```javascript JavaScript (using @solana/web3.js) theme={"system"}
  // Replace <api-key> with your Helius API key
  const { Connection } = require('@solana/web3.js');

  async function getMinimumDelegation() {
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
    try {
      const minDelegation = await connection.getStakeMinimumDelegation();
      console.log(`Current minimum stake delegation: ${minDelegation} lamports`);
      // The raw response includes context:
      // const fullResponse = await connection.getStakeMinimumDelegation('confirmed'); // Example with commitment
      // console.log(JSON.stringify(fullResponse, null, 2));
    } catch (error) {
      console.error('Error fetching stake minimum delegation:', error);
    }
  }

  getMinimumDelegation();
  ```
</CodeGroup>

### 2. Lấy số lượng ủy quyền stake tối thiểu với mức cam kết cụ thể

<CodeGroup>
  ```bash cURL theme={"system"}
  # Replace <api-key> with your Helius API key
  curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getStakeMinimumDelegation",
      "params": [
        {
          "commitment": "confirmed"
        }
      ]
    }'
  ```

  ```javascript JavaScript (using @solana/web3.js) theme={"system"}
  // Replace <api-key> with your Helius API key
  const { Connection } = require('@solana/web3.js');

  async function getMinimumDelegationConfirmed() {
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
    try {
      const minDelegationResponse = await connection.getStakeMinimumDelegation('confirmed');
      console.log(`Confirmed minimum stake delegation: ${minDelegationResponse.value} lamports at slot ${minDelegationResponse.context.slot}`);
    } catch (error) {
      console.error('Error fetching confirmed stake minimum delegation:', error);
    }
  }

  getMinimumDelegationConfirmed();
  ```
</CodeGroup>

## Mẹo dành cho nhà phát triển

* **Lamport và SOL:** Giá trị trả về được tính bằng lamport. Hãy nhớ rằng 1 SOL = 1.000.000.000 lamport.
* **Giá trị động:** Số lượng ủy quyền tối thiểu có thể thay đổi theo các tham số mạng. Bạn nên truy vấn giá trị này định kỳ hoặc trước các thao tác quan trọng thay vì mã hóa cứng. Tìm hiểu thêm về [staking](https://www.helius.dev/blog/how-to-stake-solana) trong hướng dẫn chi tiết của chúng tôi.
* **Mức cam kết:** Việc sử dụng các mức cam kết khác nhau có thể ảnh hưởng đến độ mới của giá trị trả về. `finalized` mang lại độ chắc chắn cao nhất, trong khi `processed` có thể cung cấp giá trị mới hơn nhưng chưa được cụm xác nhận đầy đủ.

Hướng dẫn này sẽ giúp bạn sử dụng hiệu quả phương thức RPC `getStakeMinimumDelegation` để truy xuất số lượng ủy quyền stake tối thiểu bắt buộc trên Solana.
