Skip to content

Instantly share code, notes, and snippets.

@casweeney
Created August 9, 2023 11:30
Show Gist options
  • Select an option

  • Save casweeney/90f58ea05610f4ef6102793ae8c81a02 to your computer and use it in GitHub Desktop.

Select an option

Save casweeney/90f58ea05610f4ef6102793ae8c81a02 to your computer and use it in GitHub Desktop.
#![cfg_attr(not(feature = "std"), no_std, no_main)]
#[ink::contract]
mod setter_getter_contract {
use ink::prelude::string::String;
/// Defines the storage of your contract.
/// Add new fields to the below struct in order
/// to add new static storage fields to your contract.
#[ink(storage)]
pub struct SetterGetterContract {
/// Stores a single `bool` value on the storage.
name: String,
}
impl SetterGetterContract {
/// Constructor that initializes the `bool` value to the given `init_value`.
#[ink(constructor)]
pub fn new(init_name: String) -> Self {
Self { name: init_name }
}
#[ink(constructor)]
pub fn default() -> Self {
Self {
name: Default::default(),
}
}
/// Simply returns the current value of our `name`.
#[ink(message)]
pub fn get_name(&self) -> String {
self.name.clone()
}
/// A message that can be called on instantiated contracts.
/// This one changes the value of the stored `name`
#[ink(message)]
pub fn set_name(&mut self, new_name: String) {
self.name = new_name;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment