In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
It is believed that many inexperienced people have no idea about how to buy and sell EOS memory ram. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
What is the most important thing for EOS RAM? We often see the word RAM next to EOS in the daily digital currency and blockchain news, but we should pay attention to its price anyway, why should we pay attention to its price, even for those who just want to learn more about smart contract development? There are basically three types of resources in Eos: bandwidth (Network), computing and computing backlog (CPU), and state storage (RAM). RAM is essentially a gas that provides resources for each transaction invoked in a smart contract. Unlike disks and CPU, which are obtained proportionately through token values, RAM needs to be purchased from eosio. The price of RAM is pre-determined by Bancor algorithm. Bancor algorithm will dynamically promote the current supply of RAM and the price base of supply and make it reach market equilibrium. Therefore, all transactions for buying and selling ram are unilateral transactions with eosio.ram. The subprime market also encourages those who do not use its RAM reserves to sell them to those who need them. Because Eosio supports the idea of free users, the burden of running the network falls on the developers. We need to reserve enough RAM for smart contracts to work properly on the Eos network.
Purchase RAM
Throughout the development of the smart contract on the EOS platform, we may encounter a situation in which our assigned RAM does not meet the requirements of the deployment contract. In this case, we need to purchase an additional ram with an EOS token to continue with the contractual deployment. The whole process can be done using the CLI tools provided by Eos-io, namely keosd and cleos. In our previous article, we have completed the process of setting up a local development environment to test smart contracts. If you have followed the steps in this article, we can use the same tools to interact with the main network and the test network and make some configuration changes.
Let's first point our cleos application to the test network node instead of the locally running nodeosd. We can create an additional alias to register this configuration.
Alias cleos-test='docker exec-I keosd / opt/eosio/bin/cleos-u http://jungle.eos9cat.com:8888-- wallet-url http://localhost:8900'
In the above command, we created the alias cleos-test to quickly interact with the eos test network node provided by eos9cat. Note that we still rely on our local wallet application to process our private keys. As long as we import the corresponding private key in the unlocked wallet.
Tip: if you want to persist the command, you can put the command in the ~ / .bashrc file (if you are on linux) and ~ / .bash_profile (for mac).
Sometimes, when you deploy an application contract with more complex logic, you may receive an error message similar to the screenshot above, indicating that the smart contract account does not have enough RAM to deploy the contract. In this case, we have to buy more ram from eosio.ram.
We can quickly check our ram allocation by issuing the following command:
Cleos-test get account ${accountname}
The quota attribute under the memory section indicates the amount of memory allocated by the account.
Now that we know how much ram we are entitled to, how can we know how much Ram we need to deploy our smart contracts? Because the Eosio blockchain uses Web Assembly to execute user-generated applications and code, we can roughly estimate the number of kilobytes required to execute a smart contract by adding the size of the * .wasm and * .abi files. In addition to calculating a rough estimate, we must also determine the number of Eos tokens required to buy ram.
The Eos blockchain platform relies on the Bancor algorithm to promote the secondary ram market through the unilateral transaction model. We can determine the Eos ram price by querying the ram market table exposed by the system contract and performing some simple calculations.
To get the EOS/KiB, we need to divide the quote.balance (connector balance) by base.balanceram (the underpaid portion of the token), and finally multiply this value by 1024 (that is, quote.balance/base.balance) * 1024. In the example of the smart contract I want to deploy, approximately 100KiB is required, which will cost about 31.70 EOS token. We can then proceed with the actual transaction by issuing the following command through Cleos.
Cleos-test system buyram-k ${payer} ${reciever} amount
The K flag will indicate the amount parameter indicating the amount of KiB to be purchased, and the system contract transaction will automatically deduct the appropriate amount of EOS token from the payer's account. If there is no kflag, the amount defaults to the number of EOS token spent. Similarly, based on the ram price, the appropriate amount of ram will be added to the account.
If we deploy the contract again now, it should succeed.
Sell RAM
For the unwanted ram currently occupied by the account, some EOS token resources can be exchanged through the price determined by the Banchor algorithm through the system contract. The process of selling ram is similar to buying ram on the eos blockchain.
Cleos-test system sellram ${account} bytes
A successful deal looks like this:
Persistent storage
Because of its flexibility, RAM is arguably the most popular resource on the Eos blockchain platform. RAM can be used not only to store intermediate computing state, but also as persistent storage. Multi-index database is a data structure in Eos, which provides the flexibility to store data according to the way the scope is defined. A multi-index database will store persistent data in a tabular format. In fact, unlike many other popular smart contract platforms, transactions in Eos smart contracts cannot return any values or variables, which means that any data captured by RAM cannot be returned to the caller through the transaction. In order to gain access to the values of variables in a smart contract, such as the results of a calculation and transaction, the data needs to be updated through a multi-index database table with a range, usually storing associated links to the data in the form of the caller's account name or the smart contract's own account name, and then retrieving the data through the gettable API with the corresponding contract name, scope, and table name.
For example, the number of EOS token that each account has stored in the multi-index database defined in the eosio.token contract, which consists of a small piece of RAM for each account that defines the scope. We can retrieve the number of token owned by an account directly from db using the following command:
Cleos-test get table eosio.token ${account} accounts
The table name in the above command is accounts, and the scope is the personal account name. It is logical to assign account balance information to the account that actually owns them. On the other hand, if we want to retrieve information about EOS token itself, we will need to look at another scope with different tables, even if the information is encoded in the same smart contract:
Cleos-test get table eosio.token EOS stats
Determining the scope and table name can be tricky, especially for contracts generated by others, which can usually be quickly retrieved by looking at the contract's abi.
The scope is more difficult, but can be determined by looking at the reference view parameters to the multi-index database in the code.
The first underlined section shows that the reference to the stats table is made using the sym parameter, which represents the SYMBOL; of token, so the scope of the table is the SYMBOL of token.
The second underlined section e describes the rows that refer to the account table when the balance is subtracted during the transaction. This line of code implies that the scope of the table account is the account name. More tutorials and information on using multi-index databases in smart contracts.
Upgrade contract
Because the connection between the smart contract itself and the multi-index database stored on the local disk is only a reference link, this feature is granted along with multiple deployments of contracts using the same account to upgrade smart contracts in the eos ecosystem. As long as the key functions of defining a multi-index database are the same in the old and new smart contracts, the data can be referenced in the new smart contracts.
In some cases, you may even find it useful to deploy empty contracts or significantly smaller contracts to release RAM for sales, while still keeping data related to the previous contract on persistent storage.
After reading the above, have you mastered how to buy and sell EOS memory ram? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.