Skip to content

Instantly share code, notes, and snippets.

@jamiebullock
Created February 3, 2022 17:41
Show Gist options
  • Save jamiebullock/acac9850c97ef182a69ee9b4dc04244a to your computer and use it in GitHub Desktop.
Save jamiebullock/acac9850c97ef182a69ee9b4dc04244a to your computer and use it in GitHub Desktop.
Elrond Adder
#![no_std]
elrond_wasm::imports!();
/// One of the simplest smart contracts possible,
/// it holds a single variable in storage, which anyone can increment.
#[elrond_wasm::derive::contract]
pub trait Adder {
#[view(getSum)]
#[storage_mapper("sum")]
fn sum(&self) -> SingleValueMapper<BigInt>;
#[init]
fn init(&self, initial_value: BigInt) {
self.sum().set(&initial_value);
}
/// Add desired amount to the storage variable.
#[endpoint]
fn add(&self, value: BigInt) -> SCResult<()> {
self.sum().update(|sum| *sum += value);
Ok(())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment