I’ve been following this tutorial.
I’ve successfully generated the teal script from the pyteal file
step5.teal.py. For completeness, here is the python script, though it can also be found on the tutorial linked above:
from pyteal import * # Address of the seller of the asset seller = Addr(<PUBLIC KEY>) asset_id = <ASSET ID> asset_price = 1000000 def smart_contract(tmpl_seller=seller, tmpl_asset_id=asset_id, tmpl_asset_price=asset_price, tmpl_max_fee=1000): # Check that the fee is not too high # otherwise an attacker could burn all the Algos of the seller # by choosing an abusive fee fee_cond = Txn.fee() <= Int(tmpl_max_fee) # Check that the approved transaction is the second one # of a group of two transactions group_cond = And( Global.group_size() == Int(2), Txn.group_index() == Int(1) ) # Check that the first transaction is a payment # of tmpl_asset_price Algos to the seller first_txn_cond = And( Gtxn.type_enum() == TxnType.Payment, Gtxn.amount() == Int(tmpl_asset_price), Gtxn.receiver() == tmpl_seller ) # Check that the second transaction (i.e., the one being approved) # is a transfer of 1 unit of asset second_txn_cond = And( Txn.type_enum() == TxnType.AssetTransfer, Txn.asset_amount() == Int(1), Txn.xfer_asset() == Int(tmpl_asset_id), # Check that the remaining assets are not sent anywhere Txn.asset_close_to() == Global.zero_address(), # Check that the account is not rekeyed # see https://developer.algorand.org/docs/features/accounts/rekey Txn.rekey_to() == Global.zero_address(), ) return And( fee_cond, group_cond, first_txn_cond, second_txn_cond ) if __name__ == "__main__": print(compileTeal(smart_contract(), Mode.Signature))
Next, I compiled the teal code into an
lsig file using the following command:
goal clerk compile -a <PUBLIC KEY> -s step5.teal -o step5.lsig
Now, using the newly generated lsig file, I try to read it using the algosdk so that I can use it as part of an atomic transfer grouped transaction:
from algosdk import algod, account from algosdk import transaction lsig_fname = 'step5.lsig' with open(lsig_fname, "rb") as f: teal_bytes = f.read() lsig = transaction.LogicSig(teal_bytes)
However, following code is raising an exception
raise error.InvalidProgram("unsupported version").
Why is this? How to fix it?