Closing an escrow contract cannot use CloseRemainerTo

Hello guys,

So this is what I am trying to achieve :

I have an Escrow account that is holding 1 ASA and some Algos to do transactions (let say 1 algo).
Then somebody buys this ASA for 10 algos. So now the Escrow account holds 0 ASA and around 11 Algos.

This works fine.

Then now is the part I am trying to make it work.
I am trying to delete the App (aka Escrow account) and empty it (with repartition) in the same Atomic transfer. I want 8 of these algos to go the 1 person (creator of the ASA), and the rest to me, like for a commission.
When I don’t specify any CloseRemainerTo, the money (8 algos) goes fine to the creator, and the app is deleted, but as soon as I specify the CloseRemainerTo, the transaction is not valid and I got :

"TransactionPool.Remember: transaction 3FG2QRBUM7357GWVTVM33YUHSKWJ73AJ7F7OKAC2PC3LTME6I7VA: cannot close: 1 outstanding assets"

So I am wondering , what am I doing wrong ? Maybe it’s an ordering of the two transactions in the atomic array ? Maybe I need to set a third transaction that does only the CloseRemainer ? Or maybe I need to un-opt from the ASA first ? or ME optIn in the ASA ?

Thanks for the Help. This is the piece of code I am using (JavaScript SDK with typescript)

             const callTxn = algosdk.makeApplicationDeleteTxn(
            const paymentTxn = algosdk.makePaymentTxnWithSuggestedParams(
                ASA_PRICE * 800000, // price is fine since it works without CloseRemainerTo)
                MY_ADDR, // This breaks everything
                new Uint8Array(0),

            algosdk.assignGroupID([paymentTxn, callTxn]) // order OK ?

            // ME I am signing the delete app call
            const signedCall = callTxn.signTxn(plateformSK)

            // The escrow account sign the payment to the creator of ASA (8 algos)
            const lsig = new algosdk.LogicSigAccount(
                new Uint8Array(Buffer.from(XX, 'base64'))
            const signedPayment = algosdk.signLogicSigTransaction(

            const signed = [signedPayment.blob, signedCall] // Order OK ?

            const createTxId = await algodClient.sendRawTransaction(signed).do()

Thanks you guys so much!!!

This error indicates you need to close all the assets before being allowed to close fully the accounts and empty the Algos.

Closing the assets can be done using the closeRemainderTo of the asset transaction: Algorand Standard Assets (ASAs) - Algorand Developer Portal

Hey Fabrice,

Thanks for answering.
I was reading this on Github from Ryan just earlier,
So I assume that doing a transaction with 0 ASA but closeRemainderTo filled with my address BEFORE doing the one I want will do the trick ?

Thanks again

Oh ok, so I read again a bit, though about it more.

What you meant is that during the transaction of the ASA, that I set the CloseRemainderTo MY address. So it will close it.

Then I will be able to do what I want

Me again !

Sorry for spamming, but yes, what you said to me works fine. Found the good way myself.

Thanks a lot !