Programming Incentives
Explore how to design smart contracts in Solidity that rely on incentive-based triggers rather than automated execution. Understand how to handle time-based and logical triggers, motivating users to initiate essential contract functions to reduce reliance on costly external services.
We'll cover the following...
No automated execution in Solidity
The execution of any operation in a smart contract must be initiated by an externally owned account. Contracts can never initiate transactions by themselves. So, in Solidity, there is no possibility to schedule automated code execution, as we would do with a
However, some practical problems can require scheduling the automated execution of code. There are typically two things that we may want to use as triggers:
Time-based triggers: Some computations may need to be initiated after some time delay.
Example 1: Calculating loan interest (say incrementing the amount to be paid by 10% every month).
Example 2: Calculating the number of winners at the end of a time-constrained game to divide the pot among them.
Logical triggers: Some computations may need to be initiated after some logical condition is met.
Example 1: ...