# To run this script, we need to setup a PYTHONPATH to the # SmartPyBasic directory. # If the SmartPyBasic directory is ~/SmartPyBasic, then # PYTHONPATH=~/SmartPyBasic python3 demo.py # or # ~/SmartPyBasic/SmartPy.sh run demo.py # should work. import smartpy as sp class MyContract(sp.Contract): def __init__(self, myParameter1, myParameter2): self.init(myParameter1 = myParameter1, myParameter2 = myParameter2) @sp.entry_point def myEntryPoint(self, params): sp.verify(self.data.myParameter1 <= 123) self.data.myParameter1 += params # We evaluate a contract with parameters. contract = MyContract(12, 13) # We need to compile the contract. # It can be done with the following command. import smartpybasic as spb spb.compileContract(contract, targetBaseFilename = "/tmp/myContractDemo") print("Contract compiled in /tmp/myContractDemoCode.tz")
# @params : approve_to, token_id @sp.entry_point def approve(self,params): sp.verify(self.data.tokensMinted.contains(params.token_id)) sp.verify( sp.sender == self.data.tokenIdToOwner[params.token_id]) self.data.tokenApprovals[params.token_id] = params.approve_to # @params : f, t, token_id @sp.entry_point def transferFrom(self, params): # check if token exists sp.verify(self.data.tokensMinted.contains(params.token_id)) # check if approver has the token sp.verify( params.f == self.data.tokenIdToOwner[params.token_id]) # check for approval sp.verify(sp.sender == self.data.tokenApprovals[params.token_id]) # transfer self.transderDataToken(params.f, params.t, params.token_id) # We evaluate a contract with parameters. contract = DataTokenizer("state","ST",sp.address("tz1hdQscorfqMzFqYxnrApuS5i6QSTuoAp3w")) # We need to export the compile the contract. # It can be done with the following. import smartpybasic as spb spb.compileContract(contract,targetBaseFilename = "./contract_build/Contract") print("Contract compiled in ./contract_build/ContractCode.tz")
import smartpy as sp class PhraseKeeper(sp.Contract): def __init__(self, initialPhrase): self.init(phrase=initialPhrase) # We evaluate a contract with parameters. contract = PhraseKeeper({ "Name": "John", "Identity": "17021234", "Diploma Type": "Computer Science", "Credential Number": "UET1234", "Signature": "sign" }) # We need to compile the contract. # It can be done with the following command. import smartpybasic as spb spb.compileContract(contract, targetBaseFilename='./backend/michelson/') print("Contract compiled in michelson")
# SmartPyBasic directory. # If the SmartPyBasic directory is ~/SmartPyBasic, then # PYTHONPATH=~/SmartPyBasic python3 demo.py # or # ~/SmartPyBasic/SmartPy.sh run demo.py # should work. import smartpy as sp class MyContract(sp.Contract): def __init__(self, myParameter1, myParameter2): self.init(myParameter1=myParameter1, myParameter2=myParameter2) @sp.entry_point def myEntryPoint(self, params): sp.verify(self.data.myParameter1 <= 123) self.data.myParameter1 += params # We evaluate a contract with parameters. contract = MyContract(12, 13) # We need to compile the contract. # It can be done with the following command. import smartpybasic as spb spb.compileContract(contract, targetBaseFilename='') print("Contract compiled in /tmp/myContractDemoCode.tz")