Skip to content
On this page

Offchain views and signatures โ€‹

Offchain views โ€‹

Another way to deal with offchain with is to use

TZComet. :::

To deal with offchain views in scenario, you can create a contract with a method that takes the storage of the platform and the offchain view params as an argument and reproduce the offchain view computation.



import smartpy as sp
gp ="state_channel_games/")

class TestView(sp.Contract):
    def __init__(self, c, f):
        self.c = c
        self.f = f.f
        self.init(result = sp.none)

    def compute(self, data, params): = data
        b = sp.bind_block()
        with b:
            self.f(self.c, params) = sp.some(b.value)

if "templates" not in __name__:
    sc = sp.test_scenario()
    platform_addr = sp.address("KT1V8pmoHLq6obLb3q7D6XfordUA5G1K7xkb")
    c1 = gp.GamePlatform(admins = sp.set([admin.address]), self_addr = platform_addr)
    c1.address = platform_addr

    sc.h2("Offchain new_game")
    offchain_new_game = TestView(c1, c1.offchain_new_game)
    sc += offchain_new_game

    sc.h2("Offchain play")
    offchain_play = TestView(c1, c1.offchain_play)
    sc += offchain_play

    constants = #...
    new_game_signatures = # ...

    offchain_new_game.compute(sp.record(data =, params = sp.record(constants = constants, params = sp.pack(sp.unit), signatures = new_game_signatures))).run(sender = player1.address)
    game = sc.compute(

Signatures โ€‹

All signatures can be done in scenario by putting the secret key of the signer.

That's useful for tests.

A complete example is available here: