Skip to content

Instantly share code, notes, and snippets.

@a6b8
Last active July 21, 2023 20:03
Show Gist options
  • Select an option

  • Save a6b8/e6baafbad2e42e4a259c10b6a3dcc836 to your computer and use it in GitHub Desktop.

Select an option

Save a6b8/e6baafbad2e42e4a259c10b6a3dcc836 to your computer and use it in GitHub Desktop.
import {
Field,
SmartContract,
state,
State,
method,
} from 'snarkyjs';
export class Square extends SmartContract {
@state(Field) num = State<Field>();
init() {
super.init();
this.num.set( Field( 3 ) );
}
@method update( square: Field ) {
const currentState = this.num.get();
this.num.assertEquals( currentState );
square.assertEquals( currentState.mul( currentState ) );
this.num.set( square );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment