🍁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.

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.


 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;
}

Last updated