> 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/a-sample-of-using-origin-flag-integration-on-binance-smart-chain-network..md).

# A Sample of using Origin Flag Integration on Binance Smart Chain Network.

If you need to get more information about ORIGINFLAG you can click [here](/psce-constants.md).

In the Pirichain PSce system, the Web3 library has been integrated to facilitate connection to the BSC (Binance Smart Chain) network and perform various operations. This integration allows for interacting with smart contracts, checking wallet balances, and conducting token transfers.

Additionally, the `ORIGINFLAG` constant plays a crucial role. This flag ensures that certain operations are executed only on the node that initiates the request. When `ORIGINFLAG` is set to `true`, the operation is performed exclusively on the requesting node, preventing it from running on other nodes.

#### Usage and Advantages of ORIGINFLAG

* **Custom Operation Control:** `ORIGINFLAG` allows operations to be executed only on specific nodes, enhancing security across the network and avoiding unnecessary processing.
* **Security:** By limiting operations to the requesting node, unauthorized access is prevented, thereby ensuring security.
* **Performance Optimization:** Preventing redundant operations on other nodes helps improve system performance.

#### Use Cases

`ORIGINFLAG` can be employed in scenarios such as payment processing, executing custom commands, or node customization. This feature provides a flexible and secure way to manage operations in the Pirichain PSce system, tailored to the specific needs of users.

```javascript

 async function CheckMyBalanceAndSend2MePIRI()
{
    try
    {
        const myBalanceObj=await getBnbWalletBalance();
        const myBalance=parseFloat(myBalanceObj.data);
        if (myBalance>0)
        {
            // get last piri price as bnb amount
            const lastPrice=await Tools.getData('https://generator.pirisubchains.com/licence/getPIRIPrice/bnb');
            let currentPrice=0;
            if (lastPrice?.data)
                currentPrice=lastPrice.data;
            else
                return {error:1,message:'Cannot fetch last price!'};

            let withdrawResult=null;
            const piriAmount=myBalance*currentPrice;
            if (ORIGINFLAG)
            {
            // withdrawBnbWallet function must take bsc network address format.
                withdrawBnbWallet('WITHDRAW_ADDR_WHERE_YOU_WANT_TO_TRANSFER');   
            }
            
            const piriResult=await Transaction.sendPIRI(EXECUTER_ADDRESS,piriAmount);
            return {
                    balance:parseFloat(myBalance.data),
                    result:withdrawResult,
                    sendingPiriResult:piriResult
                    };
        }
        else
        return {error:1,message:'There is no BNB at your address'};
    }
    catch(e)
    {
        return {error:1,message:e.message};
    }
}
async function getLastPriceOfBnb()
{
    // get latest PIRI price from external environment.
    const lastPrice=await Tools.getData('https://generator.pirisubchains.com/licence/getPIRIPrice/bnb');
        let currentPrice=0;
        if (lastPrice?.data)
              currentPrice=lastPrice.data;
            else
              return {error:1,message:'Cannot fetch last price!'};
              return currentPrice;
}

async function checkMyBalance()
{
        const myBalanceObj=await getBnbWalletBalance();
        return myBalanceObj;
}

async function opWithdraw()
{
    // Optional option withdraws asset relavient address.
    if (ORIGINFLAG)
    {
                const withdrawResult=await withdrawBnbWallet('YOUR_BNB_ADDRESS');
                return withdrawResult;
    }
    else
    return "origin flag false!";
}


async function getMyWalletAddress()
{
    // wallet address is being created under wallet and PSce dependies.
    const result=await createBnbWallet();
    return result.data;
}

```


---

# 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/a-sample-of-using-origin-flag-integration-on-binance-smart-chain-network..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.
