1
votes

Im trying to create a function or an extrinsic that doesn't have a transaction fee for the origin, but rather totally free. I thought maby with a weight of 0 it would be solved but it still costs tokens,

#[weight = 0]

then i tried to adjust the state with an rpc call, which did some calculations but did not modify the state How can i create a function/extrinsic that is free without any transaction fee? And is it possible for rpc calls to adjust the state?

1
Sorry @Noah, but this is not a very good question that we will be able to help you with. Please look to spend some time to formulate the following: (1) What is the context of your problem? (2) What are you trying to do? (3) What have you tried? (4) What specifically can we do to help? Posting a link to your repository with a two sentence question is not the appropriate way to get help here, but if you can adjust your question, we are happy to assist. - Shawn Tabrizi

1 Answers

3
votes

This is actually very easy with Substrate.

You simply pass Pays::No to the weight of the function.

Like so:

#[weight = (100_000, DispatchClass::Normal, Pays::No)]

Here the tuple describes:

  1. The weight of the function. You should put a real value here to represent how complex this function is for your blockhain's computation.
  2. The DispatchClass of this function. The default choice is Normal
  3. The Pays option which determines if the caller will pay a fee or not.

Note that if you create an extrinsic that a user does not pay any fees, your blockchain is immediately vulnerable to DDOS attacks, as any user could spam this function at no cost.

You will need to build other layers of verification at your blockchain to make sure only valid calls to this function are propagated to other nodes.

Take a look here: https://github.com/paritytech/polkadot/blob/master/runtime/common/src/claims.rs#L386

In this case, we have some statement which we verify is correctly signed by the user making the call before the call is passed to other nodes:

https://github.com/paritytech/polkadot/blob/master/runtime/common/src/claims.rs#L592

So you must do the same if you want your blockchain to be safe with a free function like this.