Transaction rejected by ApprovalProgram when creating new app transaction

from pyteal import *

# Define the contract's logic
def approval_program():
    
    amount = Txn.amount()
    money = Int(10000000)
    
    value = amount == money
    
    return value
    

def clear_state_program():
    return Int(1)


# Compile the contract to Teal
compiled_approval = compileTeal(approval_program(), mode=Mode.Application, version=3)
compiled_clear = compileTeal(clear_state_program(), mode=Mode.Application, version=3)

When trying to deploy this smart contract via Algo-SDK:

client_approval = client.compile(compiled_approval)
binary_approval = base64.b64decode(client_approval['result'])

client_clear = client.compile(compiled_clear)
binary_clear = base64.b64decode(client_clear['result'])

global_schema = StateSchema(0, 0)
local_schema = StateSchema(0, 0)

txn = ApplicationCreateTxn(sender=sender_address,
                           sp=params,
                           on_complete=transaction.OnComplete.NoOpOC,
                           approval_program=binary_approval,
                           clear_program=binary_clear,
                           global_schema=global_schema,
                           local_schema=local_schema)

I get the following error:

error.AlgodHTTPError(m, code, j.get("data"))
algosdk.error.AlgodHTTPError: TransactionPool.Remember: transaction DWRWBTA3D4PDS67C66VWRJQEC5UU2A62VZUYGTKFPPXMRVPNUTYA: transaction rejected by ApprovalProgram

Would very much appreciate if you could let me know, what seems to be the problem.

1 Like

is zero to my knowledge in create app call

this is zero

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”

but i would say this is better:

// 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

1 Like

@scholtz

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.

Isn’t this a case?

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

1 Like

Thank you very much. I really appreciate your help. Will go and study teal script first and then go on algo-kit. It’s good to know basic. Thanks!