🍁EVM based similar approach- Token Management With PSDATA

Manage a simple token management in PSce very easily.

Attention! , Below code lines are only sample. And Pirichain has more powerful token management using with sendToken or sendPIRI 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;
}

Last updated