🍁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.
constmyTokenName="WhateverTokenName";consttokenTotalSupply=10000000;constdecimal=18;asyncfunctiontransfer(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);returnawaitMap.saveMap(JSON.stringify(PSDATA)); } }elsereturn {error:1,message:'Balance is not true format!'}; }elsereturn {error:1,message:'Insufficent Balance '+myTokenName};}asyncfunctionmint(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;returnawaitMap.saveMap(JSON.stringify(PSDATA)); } }}asyncfunctionlistTokenTransactions(skip,limit){returnawaitTransaction.listTransactions(EXECUTER_SCENARIOADDRESS,skip,limit);}asyncfunctiongetBalance(address){returnPSDATA[address]===undefined?0:PSDATA[address];}asyncfunctiongetBalanceExecuter(){returngetBalance(EXECUTER_ADDRESS);}asyncfunctiongetBalance(address){returnPSDATA[address]===undefined?0:PSDATA[address];}asyncfunctiongetCirculationSupply(){returnPSDATA['totalMinted']==undefined?0:PSDATA['totalMinted'];}asyncfunctiongetTokenName(){return myTokenName;}asyncfunctiongetTotalSupply(){return tokenTotalSupply;}asyncfunctiongetDecimal(){return decimal;}