Neo Blockchain Fees

Mar 12, 2024 11:28:29 PM

Neo N3 Fee Calculation

divides fees into two main categories: network fees and system fees. Network fees prioritize transactions, while system fees cover script executions. Fees include Invocation Fees and Verification Fees, based on CPU Fees and Storage Fees. The network committee, a node group maintaining the network, can adjust fees through the Policy native contract.

SDKs and Wallets will automatically calculate the fees before sending a transaction. The following sections provide more details on fee calculation.

Using SDKs to Calculate Fees

All transactions must include fees. Failing to calculate fees correctly can result in transaction failure. The Neo SDKs provide methods to calculate fees, such as testInvoke. Note that this calculation is done outside the smart contracts, usually in the wallet or client.

Calculating Fees using TestInvoke

Calculating Fees using CalculateFee

Using Wallet Connect to Calculate Fees

The Wallet Connect SDK can be used to calculate fees. The following example demonstrates how to calculate fees using the Wallet Connect SDK. Note that users must connect their wallet before using this method.

System Fees

Linked to computational costs, system fees are required for a transaction’s execution, including CPU and storage. These fees are burned. System fees depend on transaction steps, each with a specific cost, and encompass verification and invocation fees.

  • Formula: SystemFee = VerificationFees + InvocationFees

Invocation Fees

Charged for CPU and storage usage, these fees are configurable through network votes.

  • Formula: Invocation Fees = CPU Fees(Transaction Script) + Storage Fees

Network Fees

Based on transaction size, network fees prioritize transaction processing, especially under high network loads.

  • Formula: NetworkFee = VerificationFees + (TransactionSize * FeePerByte)

Verification Fees

For verifying user accounts or smart-contract ownership. Costs are calculated from the Verification Script execution and are capped at 0.5 GAS.

  • Formula: VerificationFees = CPU Fees(Witnesses Script) * 30

CPU Fees

Calculated from verification and invocation script executions combined in the Witness field.

Storage Fees

Applied for storage updates during transactions, charged per byte added or replaced, with discounts for data replacement.

  • Inserted Bytes Fee: Charged for new storage data.
    • Formula: InsertedBytesFee = (Key Size + Value Size) * Fee per Byte
  • Replaced Bytes Fee: Charges for data replacement, with a discount.
    • Formula: ReplacedBytesFee = FeePerByte *1 + ((ReplacedBytesSize - 1) * FeePerByte * Discount)