Traditional Gas Model

Hello,

I’m new to ICP and canister development and have recently become quite intrigued by the ambitious goals of DFINITY. The more I learn about ICP, the more potential I see in this project!

One aspect of ICP that I really appreciate is the Reverse Gas Model. I can definitely see the reasoning and potential behind it. However, it creates a challenge where it doesn’t promote public canisters where anyone can call the functions and receive a response. This is because, under the Reverse Gas Model, the developer bears the cost for all calls rather than the users making the requests.

For some of the projects I’m working on, I’d like to store canisters on-chain for public use. These projects would open up public functions for people to do things like storing data, processing data, or executing computations. However, I don’t want to bear the full cost of these canisters and would prefer if the user pays for the cycles used. Is there a way to implement a more traditional gas model where users are responsible for the cost when they call functions inside the canister, or are there other potential solutions to address this?

Thanks,

-Jetkid

2 Likes

You use this:

The caller sends cycles with each call. Your implementation (receiver) verifies that enough payment has been provided and only then processes the call, otherwise rejects it

3 Likes

Thank you! That makes sense, and I did not know that was possible. I will try implementing this today, and do some testing.

2 Likes

you can also check out this library which also includes an example:

I am not sure if there is a solution for this available in Motoko :thinking:

@jetkid do you plan to write this in Motoko?

1 Like

Thank you for the link, I will definitely check it out!

I was planning to write in Motoko, but don’t mind switching to Rust if needed. I think I could use saikatdas0790 solution using the ExperimentalCycles Library, but since it’s experimental, there’s a risk of deprecation or changes down the line.

I hate defining a predefined cost for each call, since I only want the users to pay for what they use, but this seems to be the only way I can currently get it working without my canister fronting all the cycles.

2 Likes

I think having this written in Motoko would be cool if nobody else has done that so far. I am not aware of such library at least.

regarding the ExperimentalCycles, please note that a new Motoko base library is in the works and can already be used. see following thread: Motoko Base Library Changes

if you want to implement this in Motoko, you might want to consider publishing this as a library to https://mops.one

curious what you come up with and please let us know if you face any issues implementing this! :slight_smile: