Chuyển đến nội dung chính

User Guide: Gas

ghi chú

Bạn mới làm quen với tiền mã hóa và web3?

Head to MetaMask Learn for a straightforward learning experience designed specifically for newcomers to web3. Hoàn toàn miễn phí, có sẵn bằng nhiều ngôn ngữ và bao gồm những công cụ hữu ích, chẳng hạn như những mô phỏng để giúp bạn tự tin sử dụng MetaMask.

Gas là đơn vị đo lường lượng công việc tính toán cần thiết để xử lý các giao dịch và hợp đồng thông minh. Về cơ bản đây là phí giao dịch, và thuật ngữ này bắt nguồn từ Ethereum, trong ngữ cảnh này, nó đề cập đến công việc tính toán được thực hiện trên Máy Ảo Ethereum (EVM). Kể từ khi Ethereum được thành lập, rất nhiều mạng tương thích với EVM (và không tương thích với EVM!) networks have emerged and adopted similar models.

Thuật ngữ này tương tự với xăng để khởi động động cơ ô tô: nó chính là chi phí hoạt động không ngừng thay đổi, và đôi khi còn đắt đỏ. Các hợp đồng thông minh phức tạp hơn đòi hỏi nhiều gas hơn để cung cấp năng lượng cho công việc tính toán, cũng giống như một chiếc xe to hơn, mạnh mẽ hơn cần nhiều xăng hơn để chạy.

Phương pháp tính phí gas khác nhau tùy thuộc vào từng mạng. For example, calculating gas on Ethereum used to be very complicated, but was considerably simplified with the implementation of Ethereum Improvement Protocol (EIP) 1559 in August 2021 (also known as the London Upgrade). Essentially, you pay a base fee for every unit of gas, which is burned (read: it is deleted, and disappears) upon successful completion of the transaction. On top of the base fee, you add a priority fee, again per unit of gas, the value of which depends on how quickly you want the transaction to go through.

Trên phạm vi rộng lớn của các mạng tương thích với EVM sẵn có, gas, hoặc các đơn vị thay thế có cách vận hành tương tự, về cơ bản đã trở thành phương thức tiêu chuẩn để tính chi phí giao dịch. Fees are paid in the network's native token: for example, any transaction on Ethereum requires ETH; using BSC requires BNB; using Polygon requires POL (previously MATIC). Some networks have adopted Ethereum's EIP-1559 model wholesale, such as Polygon, whilst others have made adjustments, including Avalanche, for their C-Chain (which burns both the base fee and priority fee, rather than just the former).

Nếu bạn muốn tìm hiểu sâu thêm về cách hoạt động của gas trên Ethereum, hãy xem tại đây.

Sau đây là một số thông tin quan trọng khi làm việc với gas trong MetaMask:

The gas limit (units of gas used)

The gas limit is the maximum number of units of gas you are willing to pay for in order to carry out a transaction or EVM operation. Các hoạt động khác nhau cần có lượng đơn vị gas khác nhau. A normal transaction sending ETH or a token normally costs 21,000 gas, whereas an ERC-20 token approval requires 45,000. Many networks, such as EVM-compatible blockchain Harmony, use an identical model in which standard transactions also cost 21,000 gas.

thông tin

Tôi có cần chỉnh sửa hạn mức phí gas không?

Không! MetaMask tự động đặt hạn mức phí gas của bạn tùy thuộc vào kiểu giao dịch bạn đang thực hiện. Trong đa số trường hợp, số lượng này đủ để hoàn thành giao dịch của bạn. If you want to check or edit it, make sure you have advanced gas controls turned on and hit the button next to the gas information on the transaction confirmation screen that reads 'Market', 'Low', or 'Aggressive'.

The base fee

Every block on the Ethereum network has a base fee determined by network demand: the base fee is based on the block size of the block before it, compared against a target block size (where size refers to the total amount of gas used for all the transactions the block includes). If the size of the previous block exceeds the target, the base fee for the next block increases by 12.5%, leaving you, the user (or your wallet), with absolute certainty as to the base fee of the upcoming block. Tổng phí gas của bạn tối thiểu phải bằng mức giá này để được cân nhắc bao gồm trong khối đó.

The priority fee

The priority fee, also referred to as the "miner tip", incentivizes the miner to prioritize your transaction.

Naturally, whether this does actually go to a miner depends on the consensus mechanism they use: Ethereum mainnet became a Proof of Stake network following the Merge in September 2022, so the priority fee goes to validators instead of miners.

The max fee

Phí tối đa là tổng số tiền toàn cầu được trả cho giao dịch của bạn. Nó được tính như sau: (phí cơ sở + phí ưu tiên) x đơn vị gas được sử dụng. MetaMask initially sets this amount based on the previous block's history. Tuy nhiên, người dùng có thể chỉnh sửa số tiền này thông qua cài đặt tùy chỉnh (xem bên dưới). Chênh lệch giữa phí tối đa cho mỗi gas và (phí cơ sở + phí ưu tiên tối đa mỗi gas) được "trả lại" cho người dùng.


Basefee

Additional Concepts

Gwei

Gwei là đơn vị nhỏ nhất của ether, viết tắt của gigawei (hay 1.000.000.000). Gwei được sử dụng cho phí gas, hay đúng hơn là các khoản thanh toán được người dùng chi trả để bù đắp cho năng lượng tính toán cần có để xử lý và xác thực các giao dịch trên chuỗi khối Ethereum.

Các mạng khác cũng có xu hướng tính chi phí bằng gwei – ví dụ: Fantom, Harmony và Avalanche.

Slippage

Trượt giá là phần trăm chênh lệch dự kiến giữa giá được báo và giá thực thi.

Gas fee

Gas fee refers to the transaction fee on the Ethereum blockchain. It is what users pay to get their transaction validated, or completed.

Base fee

Được tạo bởi giao thức. Đại diện cho bội số của "lượng gas sử dụng" tối thiểu cần có để một giao dịch được đưa vào một khối (ví dụ: để hoàn tất một giao dịch). Đây là phần phí giao dịch được tiêu thụ.

Advanced Gas Controls

Nếu bạn muốn đi sâu vào cốt lõi của việc kiểm soát gas (có thể hữu ích nếu bạn đang thử nghiệm một dapp chẳng hạn), MetaMask có thể làm điều đó! See the full article here.

FAQs

Tại sao tôi phải trả phí gas cho một giao dịch thất bại?

Có thể hoàn lại phí gas của tôi không?

Cách tăng tốc hoặc hủy giao dịch đang chờ xử lý?

Cách ước tính phí gas

Why are my gas fees so high?

Error: [ethjs-query] while formatting outputs from RPC (transaction underpriced error)

How to fix "insufficient funds" error or greyed-out confirm button

Was this helpful?
Connect MetaMask to provide feedback
What is this?
This is a trial feedback system that uses Verax to record your feedback as onchain attestations on Linea Mainnet. When you vote, submit a transaction in your wallet.