so the approval program returns false, thus is rejected
for the record i do not do much python teal coding… i prefer the tealscript… there you define special method which is called on deploy app
for prompt to chatgpt he states following… the prompt: “write me tealscript program which has a constructor which sets the amount to global state, and method checkAmount which returns true if the amount in the tx from parameter is equal to the global state variable. please check the internet on how to write the tealscript smart contract”
// Import TEALScript modules
import { Contract } from '@algorandfoundation/tealscript';
// Define the global state schema
class MyContract extends Contract {
// Declare the global state variable
amount = GlobalStateKey<uint64>({ key: 'a' });
// Constructor to initialize the global state variable
createApplication(amount: uint64): void {
// Set the initial amount in global state
this.amount = amount;
}
// Method to check if the transaction amount matches the stored amount
checkAmount(tx: Txn): boolean {
// Compare the given amount with the global state variable
if (tx.typeEnum === TransactionType.AssetTransfer) {
const xfer = txAssetADeposit as AssetTransferTxn;
return xfer.assetAmount == this.amount
} else if (txAssetADeposit.typeEnum === TransactionType.Payment) {
const payTx = txAssetADeposit as PayTxn;
return payTx.amount == this.amount;
} else {
assert(false, 'Unsupported tx type');
}
return false;
}
}
i have not tried to compile this, but it should work i think… if you try to compile it the typescript safe client is generated which helps you also with suggestions of parameters how to call it
Thank you for your reply. I thought when you deploy an Algorand PyTeal smart contract, you are not immediately executing it. Instead, you’re deploying the contract code to the Algorand blockchain, which makes it available for execution in the future.
So, deployment itself doesn’t execute the contract. It only registers it on the blockchain, allowing future transactions to invoke and execute the contract when needed.
no, the approval program runs on deploy new contract… in the pure teal there is indication if the app id is zero then it is the deploy of the contract and people can this way deploy the contracts only if it meets some logic, for example the price at the oracle contract is at some level or whatever…
and btw, the pyteal is to my knowledge one year old thing… algo has moved to the pure python smart contracts… try to install algokit first and use algokit init to initiate the sample python/tealscript code for you and you will have the samle of the tests as well and i dont remember if they already allowed line by line debugging but for tealscript it is on roadmap pretty soon if not launched already