πŸŽ›οΈDeveloper Guide

Introduction

STRIKE is designed to streamline interactions with canisters (smart contracts) on the Internet Computer Protocol (ICP).

This guide provides an overview of how STRIKE operates, including setup instructions, action creation, and sharing through platforms like Twitter (X).

To interact with STRIKE URLs and the canisters they reference, you must install the STRIKE Chrome extension.

Getting Started with a Simple Example

Let's begin with a fundamental example: a "Hello" backend on the Internet Computer.

use candid::Principal;
use ic_cdk::{query, update};
use std::cell::RefCell;

struct State {
    owner: Principal,
}

impl Default for State {
    fn default() -> Self {
        Self {
            owner: Principal::anonymous(),
        }
    }
}

thread_local! {
    static STATE: RefCell<State> = RefCell::new(State::default());
}

#[query]
fn hello() -> String {
    let caller = ic_cdk::caller();
    format!("Hello, {}!", caller)
}

#[update]
fn set_owner(owner: Principal) -> String {
    STATE.with(|s| s.borrow_mut().owner = owner);
    format!("Owner is {}!", owner)
}

#[query]
fn get_owner() -> Principal {
    STATE.with(|s| s.borrow().owner)
}

ic_cdk::export_candid!();

This canister implementation includes three functions: hello, set_owner, and get_owner.

We will now proceed with implementing these functions.

Creating the Actions JSON File

To enable interactions with the canister, we need to create an actions.json file that defines the permitted actions.

This JSON file includes metadata such as action labels, descriptions, canister IDs, and the available actions ("Hello", "Get Owner", and "Set Owner").

Create a new file named actions.json and add the following configuration:

{
  "icon": "https://strike.oranj.co/hello-strike.png",
  "homepage": "https://strike.oranj.co",
  "label": "Simple Ownership",
  "title": "Simple Ownership",
  "description": "Demo canister integration with STRIKE",
  "canisterId": "ea6rm-nyaaa-aaaak-ak2wa-cai"
}
  • icon: A URL linking to the image that will be displayed at the top of the interface.

  • homepage: A string that represents the canister’s homepage.

  • canisterId: The identifier of the canister.

For further details on these values, refer to the Actions page.

Implementing the Functions for Interaction

Next, we need to define the available actions in the JSON file.

Append the following script to actions.json:

{
  ...
  "actions": [
    {
      "label": "Hello",
      "method": "hello",
      "type": "query",
      "uiParameters": [],
      "input": [],
      "inputParameters": [],
      "output": ["Text"]
    },
    {
      "label": "Get Owner",
      "method": "get_owner",
      "type": "query",
      "uiParameters": [],
      "input": [],
      "inputParameters": [],
      "output": ["Principal"]
    },
    {
      "label": "Set Owner",
      "method": "set_owner",
      "type": "update",
      "uiParameters": [
        {
          "name": "owner",
          "label": "Enter a new owner",
          "candidType": "Principal"
        }
      ],
      "input": ["Principal"],
      "inputParameters": ["{owner}"],
      "output": []
    }
  ]
}

This configuration defines three actions:

  • Hello: A query method that returns a greeting message.

  • Get Owner: A query method that retrieves the current canister owner.

  • Set Owner: An update method that allows modifying the canister owner.

By setting up these actions, we enable seamless interaction with the canister through STRIKE.

Hosting and Deployment

Once the actions.json file is created, it can be hosted on any public platform (e.g., GitHub, a custom domain, or any publicly accessible location).

Deploy the code and use the generated link to test it on strike.oranj.co.

Registering on the STRIKE registry

To enable STRIKE card unfurling on Twitter/X, you must register it in the STRIKE registry. Once your STRIKE card is ready, you can fill out this form for registration.

Conclusion

In this guide, we explored the fundamentals of STRIKE, canister integration, and strike card routing. We also demonstrated a simple ownership model using STRIKE Actions.

Last updated