Skip to content

contract syntax #11

Description

@pyramation

state on the class itself

import { BigNumber } from "jsd-std";

export class Counter {
  private count: BigNumber;

  constructor(initialState: BigNumber) {
    this.count = initialState;
  }

  public increment(amount: BigNumber): void {
    this.count = this.count.add(amount);
  }

  public decrement(amount: BigNumber): void {
    if (this.count.lt(amount)) {
      throw new Error("Count cannot be negative");
    }
    this.count = this.count.sub(amount);
  }

  public getCount(): BigNumber {
    return this.count;
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions