Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Resource Price Calculator with EOS

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "EOS how to achieve the resource price calculator". In the daily operation, I believe many people have doubts about how to achieve the resource price calculator in EOS. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to achieve the resource price calculator in EOS". Next, please follow the editor to study!

1. Resource types in EOS

On the EOS block chain, there are three types of resources available to EOS accounts:

State storage: RAM, or memory

Bandwidth and log storage: Bandwidth, or network bandwidth

Calculation: CPU

2. The utilization of EOS resources.

In the EOS blockchain, memory / RAM is used to hold the state of the blockchain, such as transaction delegation books and account balances. These states are usually accessed by application logic.

Network bandwidth measures your average bandwidth consumption over the past 3 days. Every time you send an action or transaction, it temporarily consumes some bandwidth resources.

CPU measures your average use of computing resources over the past three days, in milliseconds. Every time you send an action or transaction, it also temporarily consumes some CPU resources.

3. EOS resource allocation model.

In the EOS block chain, the network bandwidth and CPU resources are obtained by mortgage. How much bandwidth and CPU are allocated to you depends on how much EOS tokens you have mortgaged as a percentage of the total tokens held by the EOS blockchain system mortgage contracts in the past three days. The network bandwidth resources and CPU resources consumed by the sending exchange will be automatically released to you over time.

The RAM resources in EOS need to be purchased at the market price, which is automatically adjusted according to the Bancor algorithm. Unlike CPU and network bandwidth resources, occupied memory resources are not automatically released, the only way to release them is to delete data from your account status store, and then you can sell the free memory resources at market prices.

4. Resource price calculator

To calculate the price of EOS memory resources, you need to use the bancor algorithm. If you want to learn how to implement resource pricing in your EOS wallet products, you can refer to this EOS wallet development tutorial.

First, use EOS's client tool cleos command to obtain memory market data:

$cleos-u http://nodes.get-scatter.com:80 get table eosio eosio rammarket {"supply": "10000000000.0000 RAMCORE", "base": {"balance": "35044821247 RAM", "weight": "0.50000000000000000"}, "quote": {"balance": "3158350.8754 EOS", "weight": "0.50000000000000000"}}

Based on the above memory market data, the memory price can be calculated according to the following formula:

Memory price = Connector Balance / (Smart Token's Outstanding supply × CW) = 3158350.8754 EOS/ 35044821247 RAM = 0.09EOS/Kib

Where:

Connector Balance = quote.balance

Smart Token's Outstanding supply = base.balance

CW = quote.weight

EOS is the connector and RAMCORE is the smart token (smart token)

Note: there is an error in the white paper of Bancor protocol. CW is not intentionally set to 50%. For more information, please see here.

The prices of network bandwidth and CPU resources depend on the outgoing nodes, and the prices are different from each other. Let's take the outgoing block node eosnewyorkio as an example.

Or use cleos to get the basic data first:

$cleos-u https://api.eosnewyork.io/ get account eosnewyorkionet bandwidth:staked: 900.0000 EOS (total stake delegated from account to self) delegated: 0.0010 EOS (total staked delegated to account from others) used: 200 bytesavailable: 578.4 MiBlimit: 578.4 MiBcpu bandwidth:staked: 900.0000 EOS (total stake delegated from account To self) delegated: 0.0000 EOS (total staked delegated to account from others) used: 10.91 msavailable: 1.864 minlimit: 1.864 min

The calculation formula is as follows:

Net Price = (Net Staked / Net Available) / 3 = 900.0000 / (578.4 / 1024) / 3 = 0.0005 EOS/KiB/Day CPU Price = (CPU Staked / CPU Available) / 3 = 900.0000 / (1.864 / 601 000) / 3 = 0.0025 EOS/ms/Day

You can check the real-time prices of these resources here.

5. Estimate the memory resource requirements of EOS DApp

First of all, we estimate the demand and cost of memory resources. Refer to the eos node source code eos/libraries/chain/eosio_contract.cpp:

The amount of code = code_size X setcode_ram_bytes_multipliercode_size: size of wast filesetcode_ram_bytes_multiplier = 10

In addition:

Overhead_per_row_pper_index = 32 + sizeof (key) + row data for all objects which stored in DB

This results in the total memory requirements:

Ram for Dapp = Amount of code + overhead_per_row_pper_index6, estimated CPU of EOS DApp and bandwidth resource requirements

Suppose we are going to develop a DApp on EOS, which is expected to be accessed by 1000 users per day, with each user conducting 5 transactions per day.

Typically, a transaction consumes 200 bytes of bandwidth and 1ms's CPU. Therefore, we can get the following results:

Total_cpu_dapp = 1ms*5*1000 = 5000 ms/daytotal_net_dapp = 0.2 KiB/day 51000 = 1000 KiB/day

Combined with the previous resource price calculation, we get the following DApp resource cost data:

Total EOS (CPU+NET) = 1000KiB * 0.0005 EOS/KiB/Day + 5000 ms/Day * 0.0025EOS/ms/Day ~ 13 EOS/day

In other words, in order to operate this DApp and enable it to support 5000 visits per day, we need to ensure that 13 EOS resources are available on the contract account every day, which is the estimated memory, CPU and bandwidth resources we need to develop this EOS DApp. If you want to use the familiar PHP to develop EOS DApp, you can download this EOS PHP development package.

At this point, the study on "how to implement the resource price calculator in EOS" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report