Payment Upon IoT

Author: Accord Project

payment-upon-iot@0.10.0 Contract ^0.26.0 216a066db89375b78fd64ebe3d78f7f632d4d5b99f8653b67648bd95b0e45c8f

This is a payment contract that pays out a fixed amount each time a button is pressed.

Download Archive Download Compiled Archive Open in Template Playground Open in VSCode Web

Payment upon IoT Button Press

This is template pays out a fixed amount each time a button is pressed.

It responds to:

  • single press : increments a counter by 1
  • double press : decrements a counter by 1
  • long press : pays out based on the current counter and resets the counter to 0

Template Text

Upon long button press, "Dan" shall pay to "Grant" 10 USD for each short button press. A maximum of 5 payments may be made before this contract is COMPLETED.

Note: to undo a short button press the buyer may double-press the button.

Upon long button press, "Dan" shall pay to "Grant" 10 USD for each short button press. A maximum of 5 payments may be made before this contract is COMPLETED.

Note: to undo a short button press the buyer may double-press the button.
Upon long button press, {{buyer}} shall pay to {{seller}} {{amountPerUnit}} for each short button press. A maximum of {{paymentCount}} payments may be made before this contract is COMPLETED.

Note: to undo a short button press the buyer may double-press the button.
{
  "$class": "org.accordproject.paymentuponiot@0.2.0.TemplateModel",
  "buyer": "resource:org.accordproject.party.Party#Dan",
  "seller": "resource:org.accordproject.party.Party#Grant",
  "amountPerUnit": {
    "$class": "org.accordproject.money@0.3.0.MonetaryAmount",
    "doubleValue": 10,
    "currencyCode": "USD"
  },
  "paymentCount": 5,
  "$identifier": "4fdf51f3-d431-400a-b38b-3e37c83e6cea",
  "clauseId": "4fdf51f3-d431-400a-b38b-3e37c83e6cea"
}

Template Model

namespace org.accordproject.paymentuponiot@0.2.0

import org.accordproject.contract@0.2.0.Clause from https://models.accordproject.org/accordproject/contract@0.2.0.cto
import org.accordproject.runtime@0.2.0.{Request,Response} from https://models.accordproject.org/accordproject/runtime@0.2.0.cto
import org.accordproject.money@0.3.0.MonetaryAmount from https://models.accordproject.org/money@0.3.0.cto

/**
 * Lifecycle status of the contract
 */
enum ContractLifecycleStatus {
  o INITIALIZED
  o RUNNING
  o COMPLETED
}

/**
 * Request: contract signed (transitions INITIALIZED -> RUNNING)
 */
transaction ContractSigned extends Request {
  o String contractId
}

/**
 * Request: single button press — increments counter
 */
transaction SingleButtonPress extends Request {
}

/**
 * Request: double button press — decrements counter
 */
transaction DoubleButtonPress extends Request {
}

/**
 * Request: long button press — emits payment obligation
 */
transaction LongButtonPress extends Request {
}

/**
 * Request: payment received — decrements counter by units paid
 */
transaction PaymentReceived extends Request {
  o MonetaryAmount amount
}

/**
 * Response for counter-related operations
 */
transaction CounterResponse extends Response {
  o Double counter
  o Double paymentCount
}

/**
 * Event emitted when payment is due
 */
event PaymentObligationEvent {
  o MonetaryAmount amount
  o String description
}

/**
 * State for the payment upon IoT contract
 */
concept CounterState identified {
  o ContractLifecycleStatus status
  o Double counter
  o Double paymentCount
}

/**
 * The template model
 */
@template
asset TemplateModel extends Clause {
  o String buyer
  o String seller
  o MonetaryAmount amountPerUnit
  o Integer paymentCount
}

Model Dependencies

Template Logic

Find the full logic for this template on on GitHub.

State Types

Type Sample JSON
org.accordproject.runtime@0.2.0.State
{
    "$class": "org.accordproject.runtime@0.2.0.State",
    "$identifier": "0b0a0fe0-5148-11f1-b477-1d07e3e4a204"
}

Request Types

Type Sample JSON
org.accordproject.paymentuponiot@0.2.0.ContractSigned
{
    "$class": "org.accordproject.paymentuponiot@0.2.0.ContractSigned",
    "contractId": "Nostrud ad.",
    "$timestamp": "2026-05-16T17:55:28.983+01:00"
}
org.accordproject.paymentuponiot@0.2.0.DoubleButtonPress
{
    "$class": "org.accordproject.paymentuponiot@0.2.0.DoubleButtonPress",
    "$timestamp": "2026-05-16T17:55:28.986+01:00"
}
org.accordproject.paymentuponiot@0.2.0.LongButtonPress
{
    "$class": "org.accordproject.paymentuponiot@0.2.0.LongButtonPress",
    "$timestamp": "2026-05-16T17:55:28.987+01:00"
}
org.accordproject.paymentuponiot@0.2.0.PaymentReceived
{
    "$class": "org.accordproject.paymentuponiot@0.2.0.PaymentReceived",
    "amount": {
        "$class": "org.accordproject.money@0.3.0.MonetaryAmount",
        "doubleValue": 65.266,
        "currencyCode": "MUR"
    },
    "$timestamp": "2026-05-16T17:55:28.987+01:00"
}
org.accordproject.paymentuponiot@0.2.0.SingleButtonPress
{
    "$class": "org.accordproject.paymentuponiot@0.2.0.SingleButtonPress",
    "$timestamp": "2026-05-16T17:55:28.985+01:00"
}
org.accordproject.runtime@0.2.0.Request
{
    "$class": "org.accordproject.runtime@0.2.0.Request",
    "$timestamp": "2026-05-16T17:55:28.982+01:00"
}

Response Types

Type Sample JSON
org.accordproject.paymentuponiot@0.2.0.CounterResponse
{
    "$class": "org.accordproject.paymentuponiot@0.2.0.CounterResponse",
    "counter": 87.816,
    "paymentCount": 121.296,
    "$timestamp": "2026-05-16T17:55:28.989+01:00"
}
org.accordproject.runtime@0.2.0.Response
{
    "$class": "org.accordproject.runtime@0.2.0.Response",
    "$timestamp": "2026-05-16T17:55:28.988+01:00"
}

Events Types

Type Sample JSON

Technical Integration

Please refer to the Accord Project documentation for how to use a template or integrate it within your application.

View the Latest code for this template on GitHub.