Skip to content

Instantly share code, notes, and snippets.

@SilentCicero
Last active January 5, 2023 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SilentCicero/25bbd4d5b5a72e1242840c36985b0522 to your computer and use it in GitHub Desktop.
Save SilentCicero/25bbd4d5b5a72e1242840c36985b0522 to your computer and use it in GitHub Desktop.
A simple counter Sway contract.
contract;
use sway_libs::i8::I8;
abi TestContract {
#[storage(write)]
fn initialize_counter(value: u64) -> u64;
#[storage(read, write)]
fn increment_counter(amount: u64) -> u64;
}
storage {
counter: u64 = 0,
}
impl TestContract for Contract {
#[storage(write)]
fn initialize_counter(value: u64) -> u64 {
let something = I8::max();
storage.counter = value;
value
}
#[storage(read, write)]
fn increment_counter(amount: u64) -> u64 {
let incremented = storage.counter + amount;
storage.counter = incremented;
incremented
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment