> For the complete documentation index, see [llms.txt](https://smartscenarios.pirichain.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://smartscenarios.pirichain.com/psce-functions/examples/advanced-operation-withdraw-all-your-asset-from-pcse.md).

# Advanced Operation - Withdraw All Your Asset From PCse

**Is it necessary to use?**\
Its not necessary to use at each PSce. <mark style="color:red;">**But if you remove this function before creation of PSce. No one can withdraw assets from PSce if you didn't code different  withdrawal approach .**</mark>

{% code overflow="wrap" %}

```javascript
async function WithdrawAllAssetToOwnerWallet(asset_ID)
{
    if (OWNER_ADDRESS!==EXECUTER_ADDRESS)
    // Only PSce owner execute this function. otherwise return an error.
    return {error:1,data:'Only scenario owner can execute this method!'};
    
    if (asset_ID) // check asset_ID has value
    {
        if (!isNaN(parseInt(asset_ID))) // check asset_ID is numeric.
        {
            const myBalanceObject=await Transaction.getBalance(EXECUTER_SCENARIOADDRESS,-1); 
            // get Balance from PSce.
            let myBalance=parseFloat(myBalanceObject.balance);
            if (asset_ID===-1) // if its PIRI
            {
                if (myBalance<0.1) // check the balance minimum 0.1 PIRI for fee
                    return {error:1,data:'Your Piri Coin is not enough to transfer!'};
                myBalance-=0.1; // seperate for fee
                    return await Transaction.sendPIRI(OWNER_ADDRESS,myBalance); 
                    // Send asset to PSce owner wallet
            }
            else // if its a token 
            {
                if (myBalance<0.1) 
                // check the balance minimum 0.1 PIRI for fee
                    return {error:1,data:'Your Piri Coin is not enough to transfer!'};             
                const myTokenBalanceObject=await Transaction.getBalance(EXECUTER_SCENARIOADDRESS,asset_ID);
                // check PSce balance 
                let myTokenBalance=parseFloat(myTokenBalanceObject.balance);
                if (myTokenBalance>0) // check the token balance 
                    return await Transaction.sendToken(OWNER_ADDRESS,myTokenBalance,asset_ID);
                else
                return {error:1,data:'You dont have enough token balance!'};
            }

        }
    }
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://smartscenarios.pirichain.com/psce-functions/examples/advanced-operation-withdraw-all-your-asset-from-pcse.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
