Phala Network Docs
  • Home
    • 👾Phala Network Docs
  • Overview
    • ⚖️Phala Network
      • 💎Phala Cloud
      • 🥷Dstack
      • 🔐GPU TEE
    • 💎PHA Token
      • 🪙Introduction
      • 👐Delegation
        • Delegate to StakePool
        • What is Vault
        • What is Share
        • WrappedBalances & W-PHA
        • Examples of Delegation
        • Use Phala App to Delegate
        • Estimate Your Reward
      • 🗳️Governance
        • Governance Mechanism
        • Join the Council
        • Voting for Councillors
        • Apply for Project Funding
        • Phala Treasury
        • Phala Governance
        • Setting Up an Account Identity
  • Phala Cloud
    • 🚀Getting Started
      • Create Your Phala Cloud Account
      • Your First CVM Deployment
      • Explore Templates
        • Launch an Eliza Agent
        • Start from Template
    • 🪨TEEs, Attestation & Zero Trust Security
      • Attestation
      • Security Architecture
    • 🥷Phala Cloud User Guides
      • Deploy and Manage CVMs
        • Deploy CVM with Docker Compose
        • Set Secure Environment Variables
        • Deploy Private Docker Image to CVM
        • Debugging and Analyzing Logs
          • Check Logs
          • Private Log Viewer
          • Debug Your Application
        • Application Scaling & Resource Management
        • Upgrade Application
        • Deployment Cheat Sheet
      • Building with TEE
        • Access Your Applications
        • Expose Service Port
        • Setting Up Custom Domain
        • Secure Access Database
        • Create Crypto Wallet
        • Generate Remote Attestation
      • Advanced Deployment Options
        • Deploy CVM with Phala Cloud CLI
        • Deploy CVM with Phala Cloud API
        • Setup a CI/CD Pipeline
    • 🚢Be Production Ready
      • CI/CD Automation
        • Setup a CI/CD Pipeline
      • Production Checklist
      • Troubleshooting Guide
      • Glossary
    • 🔒Use Cases
      • TEE with AI
      • TEE with FHE and MPC
      • TEE with ZK and ZKrollup
    • 📋References
      • Phala Cloud CLI Reference
        • phala
          • auth
          • cvms
          • docker
          • simulator
      • Phala Cloud API & SDKs
        • API Endpoints & Examples
        • SDKs and Integrations
      • Phala Cloud Pricing
    • ❓FAQs
  • Dstack
    • Overview
    • Local Development Guide
    • Getting Started
    • Hardware Requirements
    • Design Documents
      • Whitepaper
      • Decentralized Root-of-Trust
      • Key Management Service
      • Zero Trust HTTPs (TLS)
    • Acknowledgement
    • ❓FAQs
  • LLM in GPU TEE
    • 👩‍💻Host LLM in GPU TEE
    • 🔐GPU TEE Inference API
    • 🏎️GPU TEE Benchmark
    • ❓FAQs
  • Tech Specs
    • ⛓️Blockchain
      • Blockchain Entities
      • Cluster of Workers
      • Secret Key Hierarchy
  • References
    • 🔐Setting Up a Wallet on Phala
      • Acquiring PHA
    • 🌉SubBridge
      • Cross-chain Transfer
      • Supported Assets
      • Asset Integration Guide
      • Technical Details
    • 👷Community Builders
    • 🤹Hackathon Guides
      • ETHGlobal Singapore
      • ETHGlobal San Francisco
      • ETHGlobal Bangkok
    • 🤯Advanced Topics
      • Cross Chain Solutions
      • System Contract and Drivers
      • Run Local Testnet
      • SideVM
    • 🆘Support
      • Available Phala Chains
      • Resource Limits
      • Transaction Costs
      • Compatibility Matrix
      • Block Explorers
      • Faucet
    • ⁉️FAQ
  • Compute Providers
    • 🙃Basic Info
      • Introduction
      • Gemini Tokenomics (Worker Rewards)
      • Budget balancer
      • Staking Mechanism
      • Requirements in Phala
      • Confidence Level & SGX Function
      • Rent Hardware
      • Error Summary
    • 🦿Run Workers on Phala
      • Solo Worker Deployment
      • PRBv3 Deployment
      • Using PRBv3 UI
      • PRB Worker Deployment
      • Switch Workers from Solo to PRB Mode
      • Headers-cache deployment
      • Archive node deployment
    • 🛡️Gatekeeper
      • Collator
      • Gatekeeper
  • Web Directory
    • Discord
    • GitHub
    • Twitter
    • YouTube
    • Forum
    • Medium
    • Telegram
Powered by GitBook
LogoLogo

Participate

  • Compute Providers
  • Node
  • Community
  • About Us

Resources

  • Technical Whitepaper
  • Token Economics
  • Docs
  • GitHub

More

  • Testnet
  • Explorer
  • Careers
  • Responsible Disclosure

COPYRIGHT © 2024 PHALA.LTD ALL RIGHTS RESERVED. May Phala be with you!

On this page
  • Concepts
  • Storage Deposit
  • Ink Gas Fee
  • Fee Structure
  • Storage Deposit Limit and Gas Limit
  • Transaction
  • Contract Deployment
  • Parameters

Was this helpful?

Edit on GitHub
  1. References
  2. Support

Transaction Costs

This page describes the costs to interact with low level Phat Contract (rust sdk). It may not reflect that in a higher level (e.g. Javascript-based Phat Contract).

PreviousResource LimitsNextCompatibility Matrix

Last updated 2 months ago

Was this helpful?

WARNING

This section is no longer recommended for deploying on Phala. To build and deploy securely and efficiently, please use the fully managed platform instead. Check out the doc on how to .

There are two types of the costs when interacting with a low level Phat Contract. The both costs may occur in transaction execution. Query is always free to user.

Concepts

Storage Deposit

Storage Deposit is charged for every added byte stored in the cluster (contract storage). Correspondingly, when you free some bytes from the storage, you can get refunded at the same rate. Now the rate is fixed at around 1 PHA per kbyte. (See Parameters for details.)

Ink Gas Fee

The gas fee is charged for every gas used to execute on-chain transaction. Typically a transaction takes less than 1 PHA.

Like EVM, the executed code in a transaction is measured by the virtual machine in a unit called gas. (weight in ink terminology). You must pay the gas fee calculated by gas * gasPrice to execute the transaction. Currently, gasPrice is a constant. (See Parameters for details.)

Fee Structure

The total fee required is defined by the sum of the gas fee and the storage deposit (could be negative):

fee = gas * gasPrice + storageDeposit

Storage Deposit Limit and Gas Limit

It's hard to predict how much fee will be charged before actually executing the transaction. So Phat Contract requires you to specify a limit to the gas and Storage Deposit. It ensures you will never pay more than expectation.

You need to specify gasLimit and storageDepositLimit when sending a transaction, which can be estimated by an estimation API. Then the max fee is defined below:

maxFee = gasLimit * gasPrice + storageDepositLimit

The VM charges you maxFee before executing a transaction. Once executed, the VM will refund the remaining fee to your account (maxFee - fee). If the transaction runs out of the gas or Storage Deposit, the transaction will be revered with an error (OutOfGas or StorageDepositLimitExhausted).

Transaction

A typical transaction takes less than 1 PHA, unless you store large chunk of data in the storage.

A regular transaction may involve gas fee and storage deposit. The gas fee (gas * gasPrice) is usually less than 1 PHA. The storage deposit fee is a bit more complex.

When you add an entry to the contract storage like below, you will be charged a small storage deposit. It takes a few bytes to store the key and the value.

fn set(&mut self) {
  // If the kv takes 50 bytes storage, the deposit would be 0.05 PHA.
  self.a_map.insert("key".to_string(), "value".to_string())
}

However, you may also remove the storage item like below. In this case, the caller will get a refund as the storage deposit.

fn clear(&mut self) {
  // If the kv takes 50 bytes storage, the refund would be 0.05 PHA.
  self.a_map.remove("key".to_string())
}

Contract Deployment

Deploy (instantiate in ink terminology) a contract may take anywhere from <0.1 PHA to >1000 PHA.

In low level Phat Contract, you need to upload the WASM code to the storage before instantiating it. Usually the uploading step takes much more than instantiation.

The uploaded code takes twice the space in the storage. For example, if you upload a 500kb WASM file, it stores around 1mb file in the storage. You will need to pay 1000 PHA as the storage deposit.

Once the code is uploaded, you can instantiate the contract with the code hash. The VM will call the constructor function to initialize the contract. This step happens in the same way as executing a transaction. It will charge you gas fee as usual. It may also charge you additional storage deposit, if you write to the storage in the constructor.

Typically, you pay a relatively large storage deposit for uploading, and a small gas fee for instantiating. However, sometimes you may deploy existing contracts. So you only pay a minor fee in the instantiating step, not the uploading step.

Parameters

gasPrice = 5
depositPerByte = 1 * PHA/KB = 1.000953674316 PHA
depositPerItem = 0.030517578125 PHA

It's possible to free the storage deposit for uploaded contracts, but it's a rare case in the reality. Every uploaded code has a reference counter. If there's no contract instance referring your code, you can get the storage deposit back. To terminate a contract to reduce the reference, call env.terminate_contract() ()

🆘
Phala Cloud
get started
doc