> 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/th/phatthana/sung-khuen/kham-nun-gas.md).

# ประมาณค่า Gas

ค่าธรรมเนียมของธุรกรรม (หรือ "gas fees") อาจแตกต่างกันอย่างมากขึ้นอยู่กับกิจกรรมบน network ดังนั้นการมีวิธีการประมาณค่าที่เชื่อถือได้จึงเป็นสิ่งสำคัญสำหรับประสบการณ์การใช้งานที่ราบรื่น

{% hint style="warning" %}
เพื่อให้แน่ใจว่าธุรกรรมของคุณจะไม่ติดสถานะ "pending" นานเกินไป คุณควรรวมค่าธรรมเนียมให้เพียงพอ:

* ค่า gas fee ขั้นต่ำ: 2,501 Gwei
* ค่า priority fee ขั้นต่ำ: 1 Gwei
  {% endhint %}

## หมายความว่าอย่างไรสำหรับนักพัฒนา Chiliz Chain?

เช่นเดียวกับ blockchain ทั่วไป คุณต้องจ่าย gas สำหรับทุกธุรกรรมบน Chiliz Chain

สิ่งสำคัญคือการสร้างสมดุลระหว่างความคุ้มค่าและความรวดเร็วในการยืนยันธุรกรรม เพื่อหลีกเลี่ยงธุรกรรมที่ล้มเหลวหรือล่าช้า การอัปเดตการประมาณค่า gas ให้เป็นปัจจุบันช่วยป้องกันทั้งการจ่ายมากเกินไปและน้อยเกินไป

## วิธีทำแบบ native

หากคุณต้องการวิธีที่เรียบง่าย คุณสามารถใช้คำร้องขอ [cURL](https://curl.se/) ไปยัง [Chiliz Chain RPC server](/th/phatthana/phuenthan/tho-chiliz-chain/tho-rpc.md) ดูรายละเอียดได้ที่: [เคล็ดลับและเทคนิค](/th/phatthana/phuenthan/tips-and-tricks.md#how-to-get-the-current-gas-price)

## วิธีทำผ่าน explorer API

ทั้ง [Chiliscan](https://chiliscan.com/) และ [Chiliz Block Explorer](https://scan.chiliz.com/) มี API ที่ให้คุณดึงข้อมูลราคา gas ปัจจุบันของ Chiliz Chain ได้

{% hint style="warning" %}
คุณต้องมี API key เพื่อใช้งาน API methods/endpoints ที่มีให้
{% endhint %}

{% hint style="info" %}
ทั้งสอง explorer ยังมีหน้า "Gas tracker" ด้วย:

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

### การใช้ Chiliscan API

Chiliscan API มีเมธอด `avg-gas-price` สำหรับวัตถุประสงค์นี้:

{% 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 %}

...ซึ่งจะคืนค่า JSON string พร้อมค่าปัจจุบัน

### การใช้ Chiliz Block Explorer API

Chiliz Block Explorer API มี stats endpoint ที่ให้ข้อมูลดังกล่าว:

{% 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 จะคืนค่าซึ่งรวมถึงข้อมูลราคา gas ตัวอย่างเช่น:

```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
}
```

คุณจะต้องใช้ส่วนนี้ (ราคาเป็น Gwei):

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

{% hint style="info" %}

* `average` สร้างสมดุลระหว่างต้นทุนที่พอเหมาะและความน่าเชื่อถือในการรวมธุรกรรมในไม่กี่ block ถัดไป
* `fast` จ่ายค่าธรรมเนียมสูงสุดเพื่อกระตุ้นให้ validator จัดลำดับความสำคัญธุรกรรมของคุณทันที รับประกันการยืนยันที่เร็วที่สุดเท่าที่เป็นไปได้สำหรับความต้องการเร่งด่วน
* `slow` เสนอค่าธรรมเนียมต่ำที่สุด แต่มีความเสี่ยงที่ธุรกรรมของคุณจะค้างสถานะ pending หาก network congestion เพิ่มขึ้น
  {% endhint %}

## วิธีทำโดยใช้ Blocknative?

[Blocknative](https://www.blocknative.com/) สร้าง infrastructure เพื่อตรวจสอบและจัดการความซับซ้อนของการทำธุรกรรมบน public blockchain networks

[Gas API](https://docs.blocknative.com/gas-prediction/gas-platform) ของ Blocknative นำเสนอวิธีการดึงข้อมูลราคา gas แบบ real-time ที่เชื่อถือได้

### ขั้นตอนที่ 1: รับ key

หากต้องการใช้ Gas API ของ Blocknative ในโปรเจกต์ของคุณ คุณจะต้องมี API Key

คุณต้อง [เข้าร่วม Gas Network ก่อน](https://www.gas.network/) ซึ่งจะให้สิทธิ์เข้าถึง API key ของคุณเอง

### ขั้นตอนที่ 2: ติดตั้งการเรียก Gas API

เมื่อคุณมี API key แล้ว คุณสามารถขอการประมาณค่าธรรมเนียมสำหรับ Chiliz ได้

{% hint style="info" %}
อย่าลืมว่า chain ID สำหรับ Chiliz Chain Mainnet คือ `88888`
{% endhint %}

วิธีที่ง่ายที่สุดคือเรียก API ผ่าน REST request ตัวอย่างเช่น ผ่าน command line:

{% code overflow="wrap" %}

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

{% endcode %}

ดูข้อมูลเพิ่มเติมได้ที่ [เอกสาร 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/th/phatthana/sung-khuen/kham-nun-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.
