How to estimate RAM/CPU/NET cost for your EOS DApp
How much does it cost to develop an Dapp based EOS? This question is among the initial ones that are being asked when any development projects begins. To those who are new to EOS and really concern about the cost, here are some information for you.
Before talking about how to calculate the resource price, let’s take a general look on the types, usage and allocation of a resources first:
1. Resource types:
There are three types of resources consumed by accounts:
- State Storage (RAM)
- Bandwidth and Log Storage (Network)
- Computation and Computational Backlog (CPU)
2. Resources usuage
- RAM: Blockchain state storage is information that is accessible from application logic. It includes information such as order books and account balances
- Network Bandwidth is measured as your average consumption in bytes over the last 3 days. Net bandwidth is temporarily consumed every time you send an action or transaction
- CPU Bandwidth is measured as your average consumption in microseconds over the last 3 days. CPU bandwidth is temporarily consumed when you send an action or transaction
3. Resource allocation
- Network, CPU — staking
The Bandwidth and CPU are allocated proportional to the amount of tokens held in a 3-day staking contract. As time goes by, the consumed Network, CPU free up and you can use the same staked tokens again and again
- RAM — market purchase
You need to purchase it at the Market Price which follows Bancor Algorithm. Unlike CPU and bandwidth RAM doesn’t get freed up automatically. The only way to free it up is to delete data from the account state. Once freed up, the RAM can be sold at the market price.
4. Resource price calculator
RAM Price
To calculate the price we should use Bancor Algorithm → section 3.1
$ 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"}
RAM price = Connector Balance / (Smart Token’s Outstanding supply × CW)
= 3158350.8754 EOS / 35044821247 RAM = 0.09 EOS/Kib
Connector Balance = quote.balanceSmart Token’s Outstanding supply = base.balanceCW = quote.weightEOS is the connector, RAMCORE is the smart token
Note: There is a wrong in Bancor Protocol’s white paper, CW was not intended to be 50%, Please check here
NET/CPU Price:
These resources depend on block producer. Each producer will be cost with different price. Here is example for eosnewyorkio producer
$ 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
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*60*1000)/3 = 0.0025 EOS/ms/Day
You can check the current resource price here
5. Estimated cost for your DApp
How to calculate RAM?:
Refer: 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
Total:
Ram for Dapp = Amount of code + overhead_per_row_pper_index
How to calculate CPU/NET?
Example: You are plan to build a DApp with 1.000 users, each user take about 5 transaction/per day.
Normally, each transaction take about 200 bytes for Net, 1ms for CPU
It means:
total_cpu_dapp = 1ms*5*1000 = 5 000 ms/day
total_net_dapp = 0.2*5*1000 = 1000 KiB/day
With above price:
Total EOS (CPU+NET) = 1000KiB * 0.0005 EOS/KiB/Day + 5 000 ms/Day *0.0025EOS/ms/Day ~ 13 EOS/day
This post written at EOS Price 5$ on 20 Sep 2018