> For the complete documentation index, see [llms.txt](https://docs.chiliz.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chiliz.com/vi/phat-trien/nang-cao/uoc-tinh-phi-gas.md).

# Ước tính phí gas

Phí giao dịch (hay "phí gas") có thể thay đổi đáng kể tùy thuộc vào hoạt động của mạng, vì vậy có một phương pháp ước tính đáng tin cậy là điều cần thiết để đảm bảo trải nghiệm người dùng mượt mà.

{% hint style="warning" %}
Để đảm bảo giao dịch của bạn không bị kẹt ở trạng thái "pending" quá lâu, bạn nên đưa vào đủ để chi trả các khoản phí:

* Phí gas tối thiểu: 2.501 Gwei.
* Phí priority tối thiểu: 1 Gwei.
  {% endhint %}

## Điều này có ý nghĩa gì với các nhà phát triển trên Chiliz Chain?

Cũng như bất kỳ blockchain nào, bạn phải trả gas cho mọi giao dịch trên Chiliz Chain.

Điều quan trọng là cân bằng giữa tiết kiệm chi phí và xác nhận kịp thời để tránh các giao dịch bị thất bại hoặc bị trì hoãn. Việc cập nhật ước tính gas thường xuyên giúp bạn tránh vừa trả quá nhiều lẫn trả quá ít.

## Cách thực hiện theo phương thức gốc

Nếu bạn muốn giữ mọi thứ *đơn giản*, bạn có thể dùng một yêu cầu [cURL](https://curl.se/) đến [máy chủ RPC Chiliz Chain](/vi/phat-trien/co-ban/ket-noi-voi-chiliz-chain/ket-noi-bang-rpc.md). Xem tại đây: [Mẹo & Thủ thuật](/vi/phat-trien/co-ban/meo-and-thu-thuat.md#how-to-get-the-current-gas-price).

## Cách thực hiện qua API của block explorer

Cả [Chiliscan](https://chiliscan.com/) và [Chiliz Block Explorer](https://scan.chiliz.com/) đều cung cấp API cho phép bạn lấy giá gas hiện tại trên Chiliz Chain.

{% hint style="warning" %}
Bạn cần một API key để tương tác với các phương thức/endpoint API có sẵn.
{% endhint %}

{% hint style="info" %}
Cả hai block explorer đều có trang "Gas tracker":

* <https://chiliscan.com/insight/leaderboard/gas-tracker>
* <https://scan.chiliz.com/gas-tracker>
  {% endhint %}

### Sử dụng API của Chiliscan

API Chiliscan cung cấp phương thức `avg-gas-price` cho mục đích này:

{% embed url="<https://chiliscan.com/documentation/api/swagger>" %}

{% code overflow="wrap" %}

```bash
curl -X 'GET' \
  'https://api.routescan.io/v2/network/mainnet/evm/88888/aggregations/avg-gas-price?apikey=YourApiKeyToken' \
  -H 'accept: application/json'
```

{% endcode %}

... sẽ trả về một chuỗi JSON với giá trị hiện tại.

### Sử dụng API của Chiliz Block Explorer

API Chiliz Block Explorer có endpoint stats cung cấp thông tin đó:

{% embed url="<https://scan.chiliz.com/api-docs?tab=rest_api>" %}

```bash
curl -X 'GET' \
  'https://scan-api.chiliz.com/api/v2/stats' \
  -H 'accept: application/json'
```

Endpoint này trả về thông tin bao gồm dữ liệu về giá gas. Ví dụ:

```json
{
  "total_blocks": "508700",
  "total_addresses": "982340",
  "total_transactions": "1699427",
  "average_block_time": 25000,
  "coin_price": "0.00254957",
  "total_gas_used": "0",
  "transactions_today": "622",
  "gas_used_today": "49063630",
  "gas_prices": {
    "average": 10,
    "fast": 10,
    "slow": 10
  },
  "static_gas_price": "10.1",
  "market_cap": "420471.10604559750644",
  "network_utilization_percentage": 40.2142
}
```

Bạn sẽ muốn sử dụng phần này (giá được tính bằng Gwei):

```json
"gas_prices": {
    "average": 10,
    "fast": 10,
    "slow": 10
  },
```

{% hint style="info" %}

* `average` cân bằng giữa chi phí vừa phải và khả năng được xác nhận trong vài khối tiếp theo.
* `fast` trả mức phí cao nhất để khuyến khích các nhà xác thực ưu tiên giao dịch của bạn ngay lập tức, đảm bảo xác nhận nhanh nhất có thể cho các nhu cầu khẩn cấp.
* `slow` có phí thấp nhất nhưng tiềm ẩn rủi ro giao dịch của bạn bị kẹt ở trạng thái pending nếu mạng bị tắc nghẽn.
  {% endhint %}

## Cách thực hiện bằng Blocknative?

[Blocknative](https://www.blocknative.com/) xây dựng cơ sở hạ tầng để theo dõi và quản lý sự phức tạp của việc giao dịch trên các mạng blockchain công cộng.

[Gas API](https://docs.blocknative.com/gas-prediction/gas-platform) của Blocknative cung cấp một cách tiếp cận đáng tin cậy, theo thời gian thực để lấy giá gas.

### Bước 1: Lấy key

Để sử dụng Gas API của Blocknative trong dự án của bạn, bạn sẽ cần một API Key.

Bạn cần [tham gia Gas Network trước](https://www.gas.network/), điều này sẽ cho bạn quyền truy cập vào API key của riêng mình.

### Bước 2: Triển khai lời gọi đến Gas API

Sau khi có API key, bạn có thể yêu cầu ước tính phí cho Chiliz.

{% hint style="info" %}
Hãy nhớ rằng chain ID của Chiliz Chain Mainnet là `88888`.
{% endhint %}

Cách đơn giản nhất là gọi API qua một yêu cầu REST. Ví dụ, qua dòng lệnh:

{% code overflow="wrap" %}

```bash
curl -H "Authorization: your-apikey-here" \
  'https://api.blocknative.com/gasprices/blockprices?chainid=88888'
```

{% endcode %}

Tìm hiểu thêm trong [tài liệu Blocknative](https://docs.blocknative.com/gas-prediction/gas-platform).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.chiliz.com/vi/phat-trien/nang-cao/uoc-tinh-phi-gas.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
