Payment Upon IoT

Author: Accord Project

payment-upon-iot@1.0.1 Contract ^2.0.0 85d084b46556c1cb2fa95ad8651a5a013b33e91115cd4023de40fe97ef96be92

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@0.2.0.Party#Dan",
  "seller": "resource:org.accordproject.party@0.2.0.Party#Grant",
  "amountPerUnit": {
    "$class": "org.accordproject.money@0.3.0.MonetaryAmount",
    "doubleValue": 10,
    "currencyCode": "USD"
  },
  "paymentCount": 5,
  "$identifier": "4fdf51f3-d431-400a-b38b-3e37c83e6cea",
  "contractId": "4fdf51f3-d431-400a-b38b-3e37c83e6cea"
}

Template Model

namespace org.accordproject.paymentuponiot@0.2.0

import org.accordproject.contract@0.2.0.Contract from https://models.accordproject.org/accordproject/contract@0.2.0.cto
import org.accordproject.runtime@0.2.0.{Request,Response,State,Obligation} 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 extends Obligation {
  o MonetaryAmount amount
  o String description
}

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

/**
 * The template model
 */
@template
asset TemplateModel extends Contract {
  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.paymentuponiot@0.2.0.CounterState
{
    "$class": "org.accordproject.paymentuponiot@0.2.0.CounterState",
    "status": "INITIALIZED",
    "counter": 42.128,
    "paymentCount": 169.431,
    "$identifier": "4f772581-97d6-11f1-9df3-81e11c024ca9"
}
org.accordproject.runtime@0.2.0.State
{
    "$class": "org.accordproject.runtime@0.2.0.State",
    "$identifier": "4f772580-97d6-11f1-9df3-81e11c024ca9"
}

Request Types

Type Sample JSON
org.accordproject.paymentuponiot@0.2.0.ContractSigned
{
    "$class": "org.accordproject.paymentuponiot@0.2.0.ContractSigned",
    "contractId": "Est aliqua exercitation magna reprehenderit.",
    "$timestamp": "2026-08-14T11:50:13.720Z"
}
org.accordproject.paymentuponiot@0.2.0.DoubleButtonPress
{
    "$class": "org.accordproject.paymentuponiot@0.2.0.DoubleButtonPress",
    "$timestamp": "2026-08-14T11:50:13.720Z"
}
org.accordproject.paymentuponiot@0.2.0.LongButtonPress
{
    "$class": "org.accordproject.paymentuponiot@0.2.0.LongButtonPress",
    "$timestamp": "2026-08-14T11:50:13.720Z"
}
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": 12.567,
        "currencyCode": "BWP"
    },
    "$timestamp": "2026-08-14T11:50:13.720Z"
}
org.accordproject.paymentuponiot@0.2.0.SingleButtonPress
{
    "$class": "org.accordproject.paymentuponiot@0.2.0.SingleButtonPress",
    "$timestamp": "2026-08-14T11:50:13.720Z"
}
org.accordproject.runtime@0.2.0.Request
{
    "$class": "org.accordproject.runtime@0.2.0.Request",
    "$timestamp": "2026-08-14T11:50:13.719Z"
}

Response Types

Type Sample JSON
org.accordproject.paymentuponiot@0.2.0.CounterResponse
{
    "$class": "org.accordproject.paymentuponiot@0.2.0.CounterResponse",
    "counter": 7.951,
    "paymentCount": 85.884,
    "$timestamp": "2026-08-14T11:50:13.720Z"
}
org.accordproject.runtime@0.2.0.Response
{
    "$class": "org.accordproject.runtime@0.2.0.Response",
    "$timestamp": "2026-08-14T11:50:13.720Z"
}

Events Types

Type Sample JSON
org.accordproject.paymentuponiot@0.2.0.PaymentObligationEvent
// sample generation failed: No concrete extending type for "concerto@1.0.0.Participant".

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.