Sending signed ApplicationCreateTxn using algod client output an AlgodHTTPError

algosdk.error.AlgodHTTPError: TransactionPool.Remember: transaction R5SC7OIHV2QWMGNL3FTB5I35476ZJCALAUEAXO3QTQK7CNIHKH3A: logic eval error: assert failed pc=254

from pyteal import *

def approval_program():
    on_creation = Seq([
        Assert(Txn.application_args.length() == Int(2)),
        App.globalPut(Bytes("assetID"), Txn.application_args[1]),
        App.globalPut(Bytes("total_token_supply"), Int(0)),
        App.globalPut(Bytes("algo_balance"), Int(0)),
        App.localPut(Int(0), Bytes("user_token_balance"), Int(0)),
        Approve()
    ])

    is_creator = Txn.sender() == Global.creator_address()

    on_closeout = Seq([
        App.globalPut(
            Bytes("total_token_supply"),
            App.globalGet(Bytes("total_token_supply")) + Int(1)
        ),
        Approve()
    ])

    register = Seq([
        App.localPut(Int(0), Bytes("user_token_balance"), Int(0)),
        Approve()
    ])

    asset_id = App.globalGet(Bytes("assetID"))
    transfer = Seq([
        Assert(App.localGet(Int(0), Bytes("user_token_balance")) == Int(0)),
        Assert(App.globalGet(Bytes("total_token_supply")) > Int(0)),
        Assert(Txn.amount() >= Int(1)),

        App.globalPut(Bytes("total_token_supply"), App.globalGet(
            Bytes("total_token_supply")) - Int(1)),

        App.localPut(Int(0), Bytes("user_token_balance"), Int(1)),

        InnerTxnBuilder.Begin(),
        InnerTxnBuilder.SetFields({
            TxnField.type_enum: TxnType.AssetTransfer,
            TxnField.xfer_asset: asset_id,
            TxnField.asset_amount: Int(1),
            TxnField.asset_receiver: Txn.sender(),
        }),
        InnerTxnBuilder.Submit(),

        Approve(),
    ])

    withdraw_amount = Btoi(Txn.application_args[1])
    handle_algo_withdrawal = Seq([
        Assert(is_creator),
        Assert(withdraw_amount <= App.globalGet(Bytes("algo_balance"))),

        App.globalPut(Bytes("algo_balance"), App.globalGet(
            Bytes("algo_balance")) - withdraw_amount),

        InnerTxnBuilder.Begin(),

        InnerTxnBuilder.SetFields({
            TxnField.type_enum: TxnType.Payment,
            TxnField.amount: withdraw_amount,
            TxnField.receiver: Global.creator_address(),
        }),
        InnerTxnBuilder.Submit(),
        Approve(),
    ])

    program = Cond(
        [Txn.application_id() == Int(0), on_creation],
        [Txn.on_completion() == OnComplete.OptIn, register],
        [Txn.on_completion() == OnComplete.CloseOut, on_closeout],
        [Txn.on_completion() == OnComplete.DeleteApplication, Return(is_creator)],
        [Txn.on_completion() == OnComplete.UpdateApplication, Return(is_creator)],
        [And(Txn.on_completion() == OnComplete.NoOp,
             Txn.application_args[0] == Bytes("transfer")), transfer],
        [And(Txn.on_completion() == OnComplete.NoOp, Txn.application_args[0] == Bytes(
            "withdrawl")), handle_algo_withdrawal],
    )

    return program


def clear_state_program():
    return Approve()


if __name__ == "__main__":
    with open("test_approval.teal", "w") as f:
        compiled = compileTeal(
            approval_program(), mode=Mode.Application, version=5)
        f.write(compiled)

    with open("test_clear_state.teal", "w") as f:
        compiled = compileTeal(clear_state_program(),
                               mode=Mode.Application, version=5)
        f.write(compiled)

def compile_program(client, source_code):
    compile_response = client.compile(source_code)
    return base64.b64decode(compile_response['result'])
    local_ints = 1
    local_bytes = 0
    global_ints = 3
    global_bytes = 0
    global_schema = transaction.StateSchema(global_ints, global_bytes)
    local_schema = transaction.StateSchema(local_ints, local_bytes)

    f = open("./ASC/test_approval.teal", "r")
    approval_program_teal = f.read()

    f = open("./ASC/test_clear_state.teal", "r")
    clear_state_program_teal = f.read()

    approval_program_compiled = compile_program(
        algod_client, approval_program_teal)

    clear_state_program_compiled = compile_program(
        algod_client, clear_state_program_teal)

To help us debugging your issue, can you please show the code you used to send the transaction.

Usually, the best way to debug code is to store the transaction(s) in a file and then use the teal debugguer.

the error occurs on --client.send_transactions([signed_txn])

def create_app(client, private_key, approval_program, clear_program, global_schema, local_schema):
    sender = account.address_from_private_key(private_key)

    on_complete = transaction.OnComplete.NoOpOC.real

    params = client.suggested_params()

    txn = transaction.ApplicationCreateTxn(sender, params, on_complete,
                                           approval_program, clear_program,
                                           global_schema, local_schema)

    signed_txn = txn.sign(private_key)
    tx_id = signed_txn.transaction.get_txid()

    client.send_transactions([signed_txn])

    transaction.wait_for_confirmation(client, tx_id, 5)

    transaction_response = client.pending_transaction_info(tx_id)
    app_id = transaction_response['application-index']
    print("Created new app-id:", app_id)

    return app_id

app_id = create_app(algod_client, creator_private_key, approval_program_compiled,
                    clear_state_program_compiled, global_schema, local_schema)

Your approval program is expecting 2 arguments on application creation:

        Assert(Txn.application_args.length() == Int(2)),

but you are not providing any arguments for ApplicationCreateTxn (app_args). See py-algorand-sdk/transaction.py at b88a471b7900d24029bc68e171bb5597b6e8f6bd · algorand/py-algorand-sdk · GitHub

That makes sense… thank you!