Practical Tx Fee Management for Developers and Users
This page references how to retrieve and deposit gas fee from a practical standpoint. For more information on theoretical explanation of how gas works, see Theoretical Tx Fee Explanation
The internet computer employs a reverse gas model, necessitating a custom fee for our canister to mitigate the risks of distributed denial-of-service (DDoS) attacks and spam. As such, we created a custom fee model that automatically computes depending on the function call. Cycles are used for many reasons such as when a function needs to make an outcall to the price feed canisters, storage of balances, any sort of update calls, etc. As such we created a fee model to account for this. Fees are sent directly to a fee manager. Currently the fee manager is just our own principal but will be upgraded to automated canister that will algorithmically distribute cycles to all necessary canisters of our protocol.
To ensure that funds are being used properly by the team, the canister's fee manager is given:
Our canister functions on a "view fee then pay" approach, where you first call a function to determine the fee, then send it to a designated sub account within our canister. You will most likely have to use this reference when calling any functions in further sections.
Paying Fee
The steps to paying your fee involve:
Retrieving the gas fee in ICP
Retrieving your deposit account
Sending the ICP to the deposit account using the estimated fee in 1.
Then calling the function you'd like to deposit to.
1. Retrieving The Fee
- Retrieving Fee Candid Notation
The candid for the fee for a specific function call is
Function call is a variant as specified.
The Token type is below
For amount, please put in the exact number you plan to enter when call the specific function.
- Retrieving Fee with dfx
To call the function from the command line we give an example for borrowing 0.03 ICP equivalent to 3_000_000 ICP in integer decimal representation. For other functions, please reference the variant above and plug in the desired FunctionCall.
The steps to deposit Icp Fee involve, finding your deposit account, transferring ICP to that deposit account based on the Fee you retrieved, then calling the specified function.
2. Retrieving Deposit Account
3. Transferring ICP to Deposit Account
Given that transferring ICP is covered in the Internet Computer's official documentation and the Dfinity Ledger, we recommend visiting this link for further details on ICP transfers if you're interested: https://internetcomputer.org/docs/current/developer-docs/integrations/ledger/interact-with-ledger/. Otherwise, simply follow the code blocks provided below.
NOTE: You can always add more to your deposit account to ensure that the transaction goes through than specified in the initial fee estimate. Only the calculated amount will be taken and the rest will remain in your deposit account to #Withdraw !!!
NOTE 2: If the fee payment is too little or fails, you will not be charged anything. But you will lose time. This is especially important for those trying to liquidate others or make fast repayments!!!
- Transferring to Deposit Account with dfx
To clear up what to put in those "$XYZ" here's a concrete examplecode
4. Call the Function that you Planned to Call
Last updated