# Smart contract fee introduction

In GXChain, deploying contracts, renewing contracts, and invoking contracts will result in different amounts of fees. This document describes the fees associated with smart contracts.

# The fee of deploying contract

The fee of deploying contract is paid by the caller, and is calculated as follows:

// base_fee is 0.01GXC, contract_size is the contract size, price_per_kbyte is the cost of 1kb ram, currently 0.2GXC
fee = base_fee + contract_size / 1024 * price_per_kbyte

# The fee of updating contract

The fee of updating contract is paid by the caller, and is calculated as follows:

// base_fee is 0.01GXC, contract_size is the contract size, price_per_kbyte is the cost of 1kb ram, currently 0.2GXC
fee = base_fee + new_contract_size / 1024 * price_per_kbyte

# The fee of calling contract

The calling contract is free, but there is a handling fee when calling. The handling fee consists of three parts, ram_fee, cpu_fee and base_fee, which will be returned later.

  • ram_fee

Generated when an object is created or modified in the contract's table, ram_fee can be set to specify the associated account to pay. How ram_fee is calculated:

// ram_bytes is the number of bytes of memory occupied, price_per_kbyte_ram is the cost of 1kb ram, currently 0.2GXC
ram_fee = ram_bytes / 1024 * price_per_kbyte_ram
ram_fee payer Description
0 Contract account itself (same as _slef)
_self Contract account itself (same as 0)
sender Contract call account
original The original calling account of the contract, which is the initial calling account in the cross-contract call

Return of ram_fee: After deleting the object in the table, the fee charged at the time of creation will be returned to the payer to which the memory belongs.

  • cpu_fee

now cpu_fee unit price is 0

  • base_fee

In addition to using cpu_fee and ram_fee, the base contract fee is 0.001GXC.

Return of base_fee: The basic handling fee generated by calling the contract will be returned to the user's to-freeze balance, which needs to be collected manually by the user.

The calculation method for calling the smart contract fee is:

// base_fee is 0.001GXC, ram_fee is calculated according to the payer and occupied memory, cpu_fee is 0
fee = base_fee + ram_fee + cpu_fee