Payment Upon IoT

Author: Accord Project

payment-upon-iot@0.9.0 Contract ^0.26.0 3f6141cb769d65e18228ffbeec5071e2602a2a2e18856ade457eacb539fc0b5c

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}} {{currencyCode}} 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.1.0.TemplateModel",
  "buyer": "resource:org.accordproject.party.Party#Dan",
  "seller": "resource:org.accordproject.party.Party#Grant",
  "amountPerUnit": {
    "$class": "org.accordproject.money.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.1.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

/**
 * 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 Double amount
  o String currencyCode
}

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

/**
 * Event emitted when payment is due
 */
event PaymentObligationEvent {
  o Double amount
  o String currencyCode
  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 Double amountPerUnit
  o String currencyCode
  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": "7c58a980-50a4-11f1-a498-6b6dff021a96"
}

Request Types

Type Sample JSON
org.accordproject.paymentuponiot@0.1.0.ContractSigned
{
    "$class": "org.accordproject.paymentuponiot@0.1.0.ContractSigned",
    "contractId": "Velit labore qui Lorem aliquip.",
    "$timestamp": "2026-05-15T21:24:41.623Z"
}
org.accordproject.paymentuponiot@0.1.0.DoubleButtonPress
{
    "$class": "org.accordproject.paymentuponiot@0.1.0.DoubleButtonPress",
    "$timestamp": "2026-05-15T21:24:41.623Z"
}
org.accordproject.paymentuponiot@0.1.0.LongButtonPress
{
    "$class": "org.accordproject.paymentuponiot@0.1.0.LongButtonPress",
    "$timestamp": "2026-05-15T21:24:41.623Z"
}
org.accordproject.paymentuponiot@0.1.0.PaymentReceived
{
    "$class": "org.accordproject.paymentuponiot@0.1.0.PaymentReceived",
    "amount": 214.52,
    "currencyCode": "Irure dolore veniam incididunt minim.",
    "$timestamp": "2026-05-15T21:24:41.623Z"
}
org.accordproject.paymentuponiot@0.1.0.SingleButtonPress
{
    "$class": "org.accordproject.paymentuponiot@0.1.0.SingleButtonPress",
    "$timestamp": "2026-05-15T21:24:41.623Z"
}
org.accordproject.runtime@0.2.0.Request
{
    "$class": "org.accordproject.runtime@0.2.0.Request",
    "$timestamp": "2026-05-15T21:24:41.623Z"
}

Response Types

Type Sample JSON
org.accordproject.paymentuponiot@0.1.0.CounterResponse
{
    "$class": "org.accordproject.paymentuponiot@0.1.0.CounterResponse",
    "counter": 202.619,
    "paymentCount": 152.594,
    "$timestamp": "2026-05-15T21:24:41.624Z"
}
org.accordproject.runtime@0.2.0.Response
{
    "$class": "org.accordproject.runtime@0.2.0.Response",
    "$timestamp": "2026-05-15T21:24:41.624Z"
}

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.