javascript smart contract code example

Example: Smart Contract, JS

1# SmartPy Code
2import smartpy as sp
3
4class StoreValue(sp.Contract):
5  def __init__(self, value):
6      self.init(storedValue = value)
7
8  @sp.entry_point
9  def replace(self, value):
10      self.data.storedValue = value
11
12  @sp.entry_point
13  def double(self):
14      self.data.storedValue *= 2
15
16@sp.add_test(name = "StoreValue")
17def test():
18  scenario = sp.test_scenario()
19  scenario.h1("Store Value")
20  contract = StoreValue(1)
21  scenario += contract
22  scenario += contract.replace(2)
23  scenario += contract.double()