How to move out assets before deleting contract?

Hi everyone and thanks for the amazing support you give in this community.

In my use case, I’m deploying a smart contract that needs to be deleted after it complete its purpose.
Of course a smart contract needs a minimum availability (0.01 in my situation).
I’d like to send back to an address the remaining amount of Algos in the smart contract before deleting it.
From the docs I understand I should use close_remainder_to but I’m getting something wrong.

This is my pyTeal code:

def inner_payment_txn(amount: TealType.uint64, receiver: TealType.bytes) -> Expr:
    return Seq([
            TxnField.type_enum: TxnType.Payment,
            TxnField.sender: Global.current_application_address(),
            TxnField.amount: amount,
            TxnField.receiver: receiver,
            TxnField.close_remainder_to: App.globalGet(Bytes("Creator"))

    on_delete = Seq([
        inner_payment_txn(Int(0), Txn.sender()),

    program = Cond(
        [Txn.application_id() == Int(0), on_creation],
        [Txn.on_completion() == OnComplete.DeleteApplication, on_delete],

Is this the right way to do an inner transaction from the Contract to another Wallet before delete the contract?

This looks good (note I haven’t tested it personally).

(I’m assuming that after return return Seq(... and before on_delete, you have your main PyTeal function.)

Note that you can simplify your code by removing completely:

and removing amount and receiver from the arguments of inner_payment_txn