- [Current Cloud Units Values](#current-cloud-units-values)
- [Node Contract](#node-contract)
- [Calculating the CU](#calculating-the-cu)
- [Calculating the SU](#calculating-the-su)
- [Calculating the Billing Rate for the Contract](#calculating-the-billing-rate-for-the-contract)
- [Applying the Discounts](#applying-the-discounts)
- [Rent Contract](#rent-contract)
- [Getting the Resources](#getting-the-resources)
- [Calculating the CU](#calculating-the-cu-1)
- [Calculating the SU](#calculating-the-su-1)
- [Calculating the Billing Rate for the Contract](#calculating-the-billing-rate-for-the-contract-1)
- [Applying the Dedicated Node Discount](#applying-the-dedicated-node-discount)
- [Applying the Staking Discount](#applying-the-staking-discount)
- [Name Contract](#name-contract)
- [Applying the Staking Discount](#applying-the-staking-discount-1)
- [Public IP](#public-ip)
- [Applying the Staking Discount](#applying-the-staking-discount-2)
- [Network Usage](#network-usage)
- [Data Usage](#data-usage)
- [NU Value](#nu-value)
- [Applying the Staking Discount](#applying-the-staking-discount-3)
- [Billing History](#billing-history)
***
## Introduction
In this section, we explain how the billing works on the TFGrid by showing different examples such as node, rent and name contracts as well as public IP and network usage.
<!--
(We can add this when 3.13 is released)
This documentation can be used in parallel with the [TFGrid Pricing Calculator](https://dashboard.grid.tf/#/deploy/pricing-calculator/) available on the Dashboard.
-->
## Resources to Update
Some of the used resources should be updated whenever you try to do these calculations, these resources are the TFT price and the cloud units (SU and CU).
### Current TFT Price
TFT price can be retrieved directly through [Stellar](https://stellar.expert/explorer/public/asset/TFT-GBOVQKJYHXRR3DX6NOX2RRYFRCUMSADGDESTDNBDS6CDVLGVESRTAC47-1?asset[]=TFT-GBOVQKJYHXRR3DX6NOX2RRYFRCUMSADGDESTDNBDS6CDVLGVESRTAC47-1&filter=markets&market=USDC-GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN-1) or from the [Dashboard](https://dashboard.grid.tf/), through the price available in the header.
![image](./img/grid_billing_1.png)
### Current Cloud Units Values
The current cloud units values can be retrieved directly from TChain with the [Polkadot UI](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Ftfchain.grid.tf#/chainstate) and the current chain state.
- On the page `Chain State`, select `tfgridModule` as the `selected state query`
Before assuming that the price above is the final price, check first if your twin is eligible for any of the available staking discount levels. To understand more about discount levels, please read [this section](staking_discount_levels.md).
For this example, we assume that this twin has 18 months worth of TFTs staked, so the user will be eligible for a Gold discount level (60% discount).
The 60% discount is thus equivalent to paying only 40% of the total price, as shown below:
```
Cost with 60% discount = 0.943182 * 0.4
= 0.377273 TFT/hour
```
## Rent Contract
### Getting the Resources
You can get the resources of a node using different methods. You can use Grid Proxy, GraphQL and the Polkadot UI.
- Using Grid Proxy
- Grid Proxy API
- Go to the section [nodes endpoint](https://gridproxy.grid.tf/swagger/index.html#/GridProxy/get_nodes__node_id_)
- Click on `Try it out`
- Write the node ID
- Click on `Execute`
- Grid Proxy URL
- You can use the following URL and replace <node_id> by the node ID:
```
https://gridproxy.grid.tf/nodes/<node_id>
```
- Using GraphQL
Navigate to [ThreeFold's GraphQL](https://graphql.grid.tf/graphql), then use the following query and replace the node id with the desired node id.
```
query MyQuery {
nodes(where: {nodeID_eq: 83}) {
id
farmingPolicyId
resourcesTotal {
cru
mru
sru
hru
}
}
}
```
- TFChain and Polkadot UI
- On the page Chain State of the [polakdot UI](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Ftfchain.grid.tf#/chainstate), select `tfgridModule` as the `selected state query`
- Select `nodes(u32): Option<TfchainSupportNode>`
- Enter the node ID
- Press `Enter`
![image](./img/grid_billing_3.png)
For our example, these are the resources for node `83` that will be used for the calculations.
```
CRU = 4
SRU = 119.24
HRU = 1863
MRU = 15.55
```
### Calculating the CU
Let's calculate the CU of this deployment.
For our example, the CU value is `10 mUSD/h`. Make sure that this value is updated according to the current values.
```
CU = min( max(MRU/4, CRU/2), max(MRU/8, CRU), max(MRU/2, CRU/4) )
There's a default `50%` discount for renting a node, this discount is not related to the staking discount. For more information on dedicated node discounts, please [read this section](dashboard@@node_finder).
Before assuming that the price above is the final price, check first if your twin is eligible for any of the available staking discount levels. To understand more about discount levels, please read [this section](staking_discount_levels.md).
For this example, let's assume that this twin has 18 months worth of TFTs staked, so the user will be eligible for a Gold discount level (60% discount).
```
Cost with 60% discount = 17.86266 * 0.4
= 7.145064 TFT/month
```
## Name Contract
Let's calculate the cost of a name contract.
For our example, we use the following value from the Pricing Policy.
![image](./img/grid_billing_4.png)
This value can then be converted to USD.
```
uniqueName in USD = 2500 / 10000000
= 0.00025 USD/hour
```
Since the current TFT conversion rate is `1 USD = 100 TFT`, we have the following:
Before assuming that the price above is the final price, check first if your twin is eligible for any of the available staking discount levels. To understand more about discount levels, please read [this section](staking_discount_levels.md).
For this example, let's assume that this twin has 18 months worth of TFTs staked, so the user will be eligible for a Gold discount level (60% discount).
```
Cost with 60% discount = 0.025 * 0.4
= 0.01 TFT/hour
```
## Public IP
Let's calculate the cost of public IPs.
For our example, we use the following value from the Pricing Policy.
![image](./img/grid_billing_5.png)
This value can then be converted to USD.
```
Public IP in USD = 40000 / 10000000
= 0.004 USD/hour
```
Since the current TFT conversion rate is `1 USD = 100 TFT`, we have the following:
Before assuming that the price above is the final price, check first if your twin is eligible for any of the available staking discount levels. To understand more about discount levels, please read [this section](staking_discount_levels.md).
For this example, let's assume that this twin has 18 months worth of TFTs staked, so the user will be eligible for a Gold discount level (60% discount).
```
Cost with 60% discount = 0.4 * 0.4
= 0.16 TFT/hour
```
> Note: This value gets added to the billing rate of your deployment.
## Network Usage
Network Usage is calculated for deployments with public IPs. It's reported every hour and its cost can be calculated approximately as follows, where the data usage is the value of data sent and received:
```
network usage = data usage * NU value
```
### Data Usage
To start, let's calculate the data usage. This can be tracked with a network tool like [nload](https://github.com/rolandriegel/nload), where the total amount of data sent and received can be displayed.
![image](./img/grid_billing_6.png)
### NU Value
Let's find the NU value of this deployment.
For our example, we use the following value from the Pricing Policy.
![image](./img/grid_billing_7.png)
This value can then be converted to USD.
```
NU price in USD = 15000 / 10000000
= 0.0015 USD/hour
```
Since in our example the current TFT conversion rate is `1 USD = 100 TFT`, we have the following:
Before assuming that the price above is the final price, check first if your twin is eligible for any of the available staking discount levels. To understand more about discount levels, please read [this section](staking_discount_levels.md).
For this example, let's assume that this twin has 18 months worth of TFTs staked, so the user will be eligible for a Gold discount level (60% discount).
```
Cost with 60% discount = 0.15 * 0.4
= 0.06 TFT/hour
```
As an example, let's assume that we used a total of 10GB in the last hour, so the next hour the billing rate should be updated to:
```
Total network usage = 10GB * 0.06 TFT/hour
= 0.6 TFT/hour
```
The billing rate in the next hour should be the following:
```
hourly billing rate = actual cost of the deployment + total network usage
```
> Note: The calculated value will always be an approximation since it's not possible to manually calculate the exact value of the data used.
## Billing History
Since the billing rate gets updated hourly, you can check the billing history from [GraphQL](https://graphql.grid.tf/graphql) using the following query. Make sure to enter the proper contract ID.