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

User guide: transactions

ghi chú

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

Truy cập MetaMask Learn để có trải nghiệm học tập đơn giản, được thiết kế đặc biệt dành cho những người mới làm quen với 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.

Anatomy of a blockchain transaction

When we talk about 'transactions' on a public blockchain network, we're usually talking about interactions between two addresses; in other words, tokens, be they fungible or non, or other crypto assets being 'sent' from one address to another. Ngoài ra còn có các giao dịch được gọi là "giao dịch nội bộ", là các tương tác xảy ra giữa các hợp đồng thông minh và phần lớn nằm ngoài phạm vi của bài viết này.

Muốn có thêm thông tin?

For more on blockchain networks and how they work in general, check out our intro article here, and if you get stuck on any unfamiliar words, our glossary is always available.

For clarity's sake, nothing is actually being sent anywhere. Một mạng chuỗi khối cho phép hợp đồng thông minh như Ethereum có nhiều thành tố hoặc tính năng khác nhau. Một trong những thành tố đó là cái gọi là "máy tính" - Máy Ảo Ethereum, hay EVM - có khả năng vận hành các chương trình ("hợp đồng thông minh"). The backbone of the system, however, is a distributed ledger: imagine a spreadsheet that contains, on one side, every single Ethereum account address, and each address has a column for each type of crypto-asset that it holds.

Hãy cùng sử dụng ví dụ để minh họa. Giả sử Guillaume muốn gửi một giao dịch đến Dolores. Guillaume có 1,36 ETH trong tài khoản và anh ấy định gửi cho Dolores 0,5 ETH. Sounds like a good day for Dolores, even in a bear market.

Guillaume opens up his MetaMask, enters Dolores' address, configures the gas parameters that he's comfortable with paying, and hits'send'.

At this point, the transaction enters a local temporary holding status, known as the local memory pool, or local mempool. The transaction will then get 'picked up' by the closest node in the network; depending on Guillaume's gas settings, his transaction will be prioritized (the more Guillaume is willing to pay per unit of gas, the faster his transaction will be processed), and propagated to other nodes in the network. The nodes will do the work of verifying that Guillaume has the ETH to spend, and then will actually perform the 'transaction': the ledger will be modified; 0.5 will be debited from Guillaume's balance, and 0.5 will be credited to Dolores'.

'The moving hand, having writ, moves on': ETH didn't move through a network per se; it wasn't an email sent from Guillaume's computer to Dolores' MetaMask inbox or anything of the sort. Guillaume sent a request, authenticated by his private keys through MetaMask, to the network to debit his account and credit Dolores', and after the verification process programmed into the network's protocols, this was done.

Một giao dịch chỉ có thế: một yêu cầu gửi đến sổ cái để phân bổ lại thứ gì đó từ địa chỉ này sang địa chỉ khác.

When things go wrong

Có nhiều lý do khiến một vấn đề xảy ra. Thông thường, bản chất của chúng là "phần mềm": MetaMask có một lỗi hoặc thứ gì đó bị cấu hình sai liên quan đến mạng mà bạn đang cố sử dụng; có lỗi kết nối.

Một vấn đề phổ biến là người dùng cố gắng trả ít hơn cho giao dịch nên họ sẽ đặt hạn mức phí gas rất thấp và tình trạng mạng bị đầy đến nỗi không có khoảng trống trong bất kỳ khối nào cho một giao dịch "rẻ tiền" như vậy, đôi khi trong một khoảng thời gian rất dài: cuối cùng, giao dịch này sẽ trở nên "mất hiệu lực" và người dùng buộc phải hủy.

If you've sent a transaction and it hasn't been finalized, its status will be shown as "pending" in MetaMask.

If you sent a transaction, and it failed, the most likely cause is a lack of gas: you "ran out of gas", in other words, the transaction had a cost in gas that, when multiplied by the gas price, resulted in a total amount of the network's native currency that was greater than what you had in your account.

Info

For more on calculating gas, consult our gas guide here.

This can happen for a number of reasons, but one thing to consider is what the transaction is that you're trying to carry out. Minting an NFT during peak network traffic times can be very gas-intensive; if you're trying out a new or experimental transaction, it may be worth trying on a test network before paying real live network fees.

Confirmed transactions cannot be reversed

Once a transaction is confirmed and shows as successful, it is final and permanently recorded on the blockchain. There is nothing MetaMask or anyone else can do to revert it.

If you need to recover funds from a confirmed transaction, the only option is to contact the receiver and ask them to return the tokens via a new transaction.

You can only cancel a transaction while it is still pending — see How to speed up or cancel a pending transaction.

Fixing the problem

Key Factor #1: local or broadcast to network

Khi bạn bắt đầu chẩn đoán vấn đề mà giao dịch gặp phải, nhất là với một giao dịch đang chờ xử lý, bạn cần phải xem liệu giao dịch này có còn trong bể nhớ giao dịch cục bộ của mình không, hay liệu nó đã được đưa vào mạng và bị mắc kẹt ở đó vì lý do nào đó. If it is just in your local mempool, the solution could be as simple as locking, and unlocking, your MetaMask (make sure you know your password and have your Secret Recovery Phrase backed up before you do). Nếu nó đã được đưa vào mạng, giải pháp có thể phức tạp hơn.

Để biết thêm về cách khắc phục các vấn đề này, hãy xem các liên kết bên dưới.

Key Factor #2: Nonce

Từ này có thể mang nhiều ý nghĩa. Nó là từ rút gọn của "số chỉ được sử dụng một lần", và trong bối cảnh này, nó đại khái có nghĩa là "số giao dịch", bắt đầu từ giao dịch đầu tiên được thực hiện bởi địa chỉ gửi đó. You can get yourself into real trouble if, for example, you're firing two different transactions from different instances of MetaMask with the same account address at the same time. Your address' transactions need to be in increasing order according to their nonce. However, just as nonces are capable of causing a stuck transaction, they can be the key to getting a transaction unstuck.

For more on that technique, see here.

Next steps

Nếu bạn có giao dịch thất bại hoặc đang chờ xử lý thì hãy tham khảo các tài nguyên sau để được hỗ trợ.

How to send tokens from your MetaMask account

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

Khắc phục sự cố Uniswap

Hướng dẫn người dùng: Gas

FAQs

H: Một tài khoản trong ví của tôi có giao dịch đang chờ xử lý hoặc đang trong hàng đợi. Can I start another transaction from a different account within the same wallet?

A: Yes, you can. Số nonce được tính theo từng tài khoản, không phải theo ví.

Was this helpful?