I am designing a simple contract that doles out staking rewards. The claimant need only call a claim function specifying the amount to be claimed. However, the amount is calculated off-chain on a website, and depends on other inputs, such as time staked, token id staked. The rules are too complex to fit in the staking contract. How can I force the user to call the claim function with a pre-specified amount of tokens?

2 Answers 2


You can't force people to call your function with specific parameters. You can force failures to occur if some specific parameters are incorrect. The problem is how do we let the smart contract know if a paremeter is incorrect. The only legitimate solution is to have these values exist on chain. So either you need to post the amount on chain and have your function use that OR you can have hardcoded values(this option is not that great).

  • What if the logic for determining the amount of staking rewards is too complicated to fit on-chain? The value (reward) is dependent on the function inputs, however the dependence of the value on function inputs is complicated, and the calculation can only be done off-chain.
    – Leo
    Commented Jun 3, 2021 at 23:28
  • The blockchain has its limitations. You might have to look into solutions that allow you to do complicated computations in a provable way. I've heard of Truebit protocol but I am not sure if will be able to do your specific computation. Commented Jun 5, 2021 at 2:40

You can sign a message with the correct parameters and verify the signature before accepting the values in the contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.