Skip to content

Latest commit

 

History

History
67 lines (47 loc) · 1.35 KB

README.md

File metadata and controls

67 lines (47 loc) · 1.35 KB

scarab

Tools for working with IOTA Smart Contracts


Usage

fn init(ctx: &ScFuncContext) {
  let owner: ScAgentId = ctx.get_required_param("ownerParam");
  let token: ScHash = ctx.get_required_param("tokenParam");

  // ...
}

fn my_func(ctx: &ScFuncContext) {
  let data: ScHash = ctx.get_required_param("data");
  let time: i64 = ctx.timestamp();

  ctx.state().set("$time", &time);
  ctx.state().set("$data", &data);

  ctx.result("data", data);
  ctx.result("time", time);

  // ...
}

fn my_view(ctx: &ScViewContext) {
  let data: ScHash = ctx.state().get_value("$data");

  ctx.result("data", data);

  // ...
}

#[no_mangle]
fn on_load() {
  let exports = ScExports::new();
  exports.add_func("init", init);
  exports.add_func("myFunc", my_func);
  exports.add_view("myView", my_view);
}

References


License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.