Pirichain Smart Scenarios Documentation
  • ➰Pirichain Smart Scenario (PSce)
  • 🧿Which Industries can use easily PSces?
  • ♥️Full Support Interoperability!
  • ➰General Structure of Smart Scenarios
  • ➰PSce Working Principles And Limitations
  • ➰PSce Constants
  • ➰PSce Accumulator Object
  • ➰Simple Usage PSce
  • ➰Generating a new transaction though PSce
  • ➰What will i have if i execute a PCse
  • 💲Operation Costs
  • 🔐Double Protect! your client assets are in safe with addition authenticator code
  • 🛑Avoid these methods and situations in PSce
  • ➿PSce Functions
    • 🏁sendPIRI
    • 🏁sendToken
    • 🏁pushData
    • 🏁getBalance
    • 🏁getBalanceList
    • 🏁getPureTransaction
    • 🏁getTransaction
    • 🏁listPoolTransactions
    • 🏁findData
    • 🏁findDataWithAddress
    • 🏁findDataWithValue
      • 🏁findDataUpperThanValue
      • 🏁findDataLowerThanValue
    • 🏁getRandom
    • 🌏getData
    • 🌎postData
    • 🔓generateAuthenticator
    • 🔓verifyAuthenticator
    • 🔓getMyAuthenticatorToken
    • ❓Validators
    • 🔔Examples
      • 🍁Get PSce owner wallet balance
      • 🍁sendToken Example
      • 🍁EVM based similar approach- Token Management With PSDATA
      • 🍁Connect to EXTERNAL ENVIRONMENTS!
      • 🍁Time Based Inheritor Example
      • 🍁Token Example with Ticket Operation
      • 🍁A sample about token vesting
      • 🍁Asset Management Of Share Holders using with PSce
      • 🍁Double Protect your assets using with Pirichain Authenticator Factor
      • 🍁What an easy to build up your metaverse planet in Pirichain!
      • 🍁A new approach dependency factor using with PSce
      • 🍁Advanced Operation - Withdraw All Your Asset From PCse
      • 🍁Task Diversification and Transaction Proof (TDTP)
      • 🍁A Sample of using Origin Flag Integration on Binance Smart Chain Network.
      • 🍁Deposit/Withdraw from Foreign Chain (BSC) and Add Order , Buy and Sell Token, Just a 277 Code Lines!
      • 🍁Pirichain Decentralized Exchange (DEX) Sample Full Codes
Powered by GitBook
On this page
  1. PSce Functions
  2. Examples

EVM based similar approach- Token Management With PSDATA

Manage a simple token management in PSce very easily.

PrevioussendToken ExampleNextConnect to EXTERNAL ENVIRONMENTS!

Last updated 1 year ago

Attention! , Below code lines are only sample. And Pirichain has more powerful token management using with or functions. If you want to create a new token which used under code lines , its up your decision. But commission might be more than classic sendToken and sendPIRI functions.

Accumulator can serve many of different conditions and situations that you can use.

const myTokenName="WhateverTokenName";
const tokenTotalSupply=10000000;
const decimal=18;

async function transfer(to,amount)
{
    if (isNaN(parseFloat(amount)) || parseFloat(amount)<=0)
        return {error:1,message:'Amount cannot be wrong format or negative or zero!'};
    
    
    let myBalance=PSDATA[EXECUTER_ADDRESS];
    if (myBalance!==undefined)
    {
        if (!isNaN(parseFloat(myBalance)))
        {
            myBalance=parseFloat(myBalance);
            if (parseFloat(myBalance)-parseFloat(amount)<0)
            {
                return {error:1,message:'Insufficent Balance '+myTokenName};
            }
            else
            {
                let receiptBalance=PSDATA[to];
                if (receiptBalance===undefined)
                    receiptBalance=0;
                    receiptBalance+=parseFloat(amount);
                    
                PSDATA[to]=receiptBalance;
                PSDATA[EXECUTER_ADDRESS]-=parseFloat(amount);
                return await Map.saveMap(JSON.stringify(PSDATA));
                
            }
        }
        else return {error:1,message:'Balance is not true format!'};
    }
    else
        return {error:1,message:'Insufficent Balance '+myTokenName};
}

async function mint(mintAmount)
{
    if (isNaN(parseFloat(mintAmount)) || parseFloat(mintAmount)<=0)
        return {error:1,message:'mintAmount cannot be wrong format or negative or zero!'};
    
    if (EXECUTER_ADDRESS!=OWNER_ADDRESS)
        return {error:1,message:'This function can only be executed by Scenario Owner!'}
    else
    {
        let totalMint=PSDATA['totalMinted']==undefined?0:parseFloat(PSDATA['totalMinted']);
        totalMint+=mintAmount;
        
        if (totalMint>=tokenTotalSupply)
            return {error:1,message:'Total mint cannot be increased!'};
        else
        {
             let ownerBalance=PSDATA[OWNER_ADDRESS]==undefined
             ?
             0
             :
             parseFloat(PSDATA[OWNER_ADDRESS]);
             
             ownerBalance+=mintAmount;
             PSDATA['totalMinted']=totalMint;
             PSDATA[OWNER_ADDRESS]=ownerBalance;
             return await Map.saveMap(JSON.stringify(PSDATA));

        }
    }
}
async function listTokenTransactions(skip,limit)
{
    return await Transaction.listTransactions(EXECUTER_SCENARIOADDRESS,skip,limit);

}
async function getBalance(address)
{
    return PSDATA[address]===undefined
    ?
    0
    :
    PSDATA[address];
}

async function getBalanceExecuter()
{
    return getBalance(EXECUTER_ADDRESS);
}

async function getBalance(address)
{
    return PSDATA[address]===undefined
    ?
    0
    :
    PSDATA[address];
}
async function getCirculationSupply()
{
    return PSDATA['totalMinted']==undefined?0:PSDATA['totalMinted'];
}
async function getTokenName()
{
    return myTokenName;
}
async function getTotalSupply()
{
    return tokenTotalSupply;
}
async function getDecimal()
{
    return decimal;
}
➿
🔔
🍁
sendToken
sendPIRI