A connected object reads this contract to decide whether to switch on or off.
It reads the contract on a regular basis (typically every 5 second):
- it switches on if the end of service date is in the futur
- it switches off if the end of service date is in the past
The object is connected to the internet and executes an HTTP GET request to the Tezos blockchain on a regular basis, and reads the resulting Json answer.
Any user can transfer tezies to the contract to switch on the object for a duration determined by an exhange rate (tez to duration).
See this contract in action in the Connected Object DApp example.
|Object owner can change exchange |
|Exchange rate between tez and duration: |
|Date of end of service. Read by object to decide whether to switch on or off.|
|Date of start of service. For information only.|
|Time unit used in service duration computation.|
|Tez unit used in service duration computation.|
|Frequency of read by object.|
|Starts service. The duration d of service is computed as: d = |
|User who started service can interrupt it. It pays back the user so that only the effective duration of service is paid.|
|Owner collects payments.|
|Owner can set time unit to |
Originate a switch contract with the widget below.
Click "Connect to Wallet" button, fill the fields "Owner" and "Rate", and click "Originate".
The command sets:
ratevariable to 2.5