Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import { storage, logging } from "near-sdk-as";
// --- contract code goes below
export function incrementCounter(value: i32): void {
const newCounter = storage.getPrimitive<i32>("counter", 0) + value;
storage.set<i32>("counter", newCounter);
logging.log("Counter is now: " + newCounter.toString());
}
export function decrementCounter(value: i32): void {
const newCounter = storage.getPrimitive<i32>("counter", 0) - value;
storage.set<i32>("counter", newCounter);
logging.log("Counter is now: " + newCounter.toString());
}
export function getCounter(): i32 {
return storage.getPrimitive<i32>("counter", 0);
}
export function resetCounter(): void {
storage.set<i32>("counter", 0);
logging.log("Counter is reset!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment