Tron Blockchain, and Crypto
In this article we will cover how the Tron blockchain works as well as explain the relationship between TRX and Energy, which we hope will help those with questions to better understand some of the common issues exhibited by said blockchain, such as failed transactions due to the Out of Energy error, and Failed Transaction — Reverted error.
First of all, the most important question we have to ask is: What is a Blockchain?
Simply speaking, the blockchain is a network of computers that validates transactions. The term ‘Blockchain’ was created by joining two words: block and chain — because of its structure. Blocks of information, chained together.
Roughly speaking, when validating a transaction the computers in the blockchain network scan past transactions to confirm that the final owner of the transferred fund is the actual owner.
How are the past transactions stored?
In blocks of transactions. Each block knows which block is their predecessor, so they can navigate through the lot checking the history of the coin being transferred and from there, validate it. Bitcoin, as an example, was the first coin blockchain created. It is a relatively simple blockchain in that it can only validate one type of currency transaction. In this case, Bitcoin. Validity in this context refers to checking if the person sending the Bitcoin is the actual owner of said currency, along with some safety measures. One important thing to note is that blocks are created at a predefined time rate. Bitcoin for example, creates a new block of transactions every ten minutes.
Tron blockchain — akin to Ethereum and Binance Smart Chain — offers validation of Smart Contracts as well as the standard currency transfer. Smart Contract is a fancy term for a small computer program. In a nutshell, this program (the Smart Contract) receives inputs from the owner wallet, as well as extra inputs needed for that specific program, differing between different Smart Contracts — and from there it runs coded commands and speaks with the blockchain to see if the transaction or transfer was successful or not.
Here enters the gas fee.
Blockchains usually charge a fee for each command a Smart Contract has to run. Thus, Smart Contracts that have more commands are more expensive to run. Simply put, imagine the Smart Contract is the route you need to drive with your car, and if the route is short, you spend less gas. If the route is longer, more gas is required.
A coin transfer is often cheap, since it is simply moving a currency from one wallet to another. Now, imagine a staking contract. It is a program that has to calculate a percentage of a value using a time amount, then mint (create) that new coin and then transfer that to the person claiming the staking. Staking contracts have many more commands to run than a simple transfer, thus they require more gas fee.
One problem of computer programs is that they sometimes hang due to heavy processing, and with ‘Smart Contract’ being a fancy word for computer program they have the same issue.
A more severe scenario would be if the program freezes because of an infinite loop. An infinite loop prevents the program from finishing and thus it hangs forever. In the Smart Contract world, an infinite loop would be disastrous because the whole blockchain would be, well, blocked.
To solve this problem, Smart Contract capable blockchains added a maximum gas fee, known as fee limit. Running a Smart Contract is like making a trip with your car without having the opportunity to stop at a gas station. If you run out of gas before reaching your destination there is nothing you can do. This is the same with the Smart Contract, and if your gas fee reaches the fee limit and the program hasn’t yet returned to the blockchain saying it was successful, the blockchain then halts the Smart Contract and rolls back all changes attempted (a fund transfer is considered a change).
Now, imagine that you decided to make a trip without visiting the gas station, and you think that what you already have in the tank is enough to reach your destination. That’s the same scenario as when you don’t have the fee limit a transaction asks for. If your currency used as gas fee (Energy on Tron, ETH in Ethereum) is emptied before the Smart Contract has finished running, all processes are rolled back — and since the gas fee is paid per command, no refund is made for all commands already completed. When that happens, Tron fails the transaction with a statement of ‘Failed — Out of Energy’.
So, Tron uses Energy as gas fee. What about TRX?
TRX is a Tron coin that you can transfer between wallets as well as freeze. While frozen, the TRX is still yours, but you can’t transfer or spend it, and it can be likened to a bank application. To reward users who freeze their TRX, Tron gives them Energy. Energy from frozen TRX recharges overtime, taking twenty-four hours to recharge from 0% to 100%. Then, the Energy you pay for gas fees from frozen TRX can be considered free, since you will have it back in twenty-four hours.
On the other hand, when a user makes a transaction on Tron blockchain with no Energy available, Tron burns (removes) TRX from the user wallet to generate Energy to pay for that transaction, and if there is no more TRX available to burn before finalizing the contract Tron fails the transaction with an Out of Energy prompt. Tron is smart enough to always use the Energy available before burning TRX for Energy.
Contextualizing that with the Devikins shop, users who saw Out of Energy failures saw that error because they were, in essence, making a trip with just barely enough gas to reach their destination and no more, not even enough to make it to the gas station if they started running low. To add on, Tron bumped the gas fee higher due to the massive volume of transactions that day.
Here are transactions executed during our tests:
And here are transactions during the sale peak:
Since then, we bumped the minimum Energy and TRX balance required to buy a pack. For instance, the 40 TRX needed for a Basic Pack is not the actual fee required for the purchase, but simply a safety measure to prevent the user from having Out of Energy failures.
Another issue associated with Tron is that all TRX burned for gas fee purposes is not reflected in the wallet balance as soon as it is burned, but only after the transaction is confirmed by nineteen computers in the Tron blockchain network.
What does that mean for the shop?
The shop prevents users from purchasing NFTs if they don’t have enough Energy/TRX to buy a pack, however since the Tron blockchain doesn’t update the TRX immediately, the Devikins shop was working with faulty information and some eventual Out of Energy failures were still occurring. After noting this, we made an announcement asking users to wait one minute between pack purchases if a user was not sure if they had enough resources to pay for the gas fee.
Another issue computer programs have are bugs, and unfortunately, no system is free of those. When a Smart Contract finds a bug while executing it halts the program. On the Tron blockchain, when a bug occurs the transaction receives a Transaction Revert error and any change made to the blockchain (such as a fund transfer) is all rolled back as if that program was never run.
To contextualize the Failed Transaction — Reverted failure in regards to the Devikins Shop, we need to first talk about the IncreaseAllowance command.
If anyone checks their transaction from the Devikins shop they will see that there are two calls to the blockchain during a pack purchase. This is needed as a safety measure, as a Smart Contract can’t move funds from the user interacting with it to prevent scam Smart Contracts. The user has to actively let the Smart Contract spend their funds. This is done through Allowance. The IncreaseAllowance call is the user letting the Devikins Market contract move the DVK from the user’s wallet to the shop wallet. However, Tron blockchain wasn’t reflecting the allowance in real time, so when the Market Buy tried to move the DVK funds it was intercepted by the blockchain and the transaction was reverted. After this issue was noticed, we improved the shop to bypass this timing issue in the Tron blockchain.
In conclusion, we see these issues as a growth pain on the path to making the Blockchain more inclusive for regular gamers, as well as those interested in blockchain games from an investment perspective. Many players are experiencing their first taste of crypto because of Devikins. The shop received many updates since the opening to address the issues we’ve detailed here so that it (and in turn, us) may offer the best and most reliable experience for all of our users, crypto veterans and new players alike that view Devikins as either a gameplay opportunity, or a chance to build their portfolio.