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

Token Example with Ticket Operation

//####PIRICHAIN Smart Scenario v.1.0########
// TICKET Token Sample Scenario

// System first fetches data from external environment , 
//checks the received data where is real or fake user infos
//and then
// controls to send one TICKET Token to users and cut 10 PIRI coin for each TICKET.

 async function TryToBuyTicket(name,surname)
{
    // Checking Amount Price
    if (parseInt(AMOUNT)<10 )
        return {error:1,message:'You must send 10 PIRI Coin for buy ticket!'};

    const userPiriBalance=await Transaction.getBalance(EXECUTER_ADDRESS,-1);

    if (parseFloat(userPiriBalance.balance)<10)
       return {error:1,message:'You dont have enough Piri Coin to buy ticket!'};

    let result=await Tools.getData('https://dummyjson.com/users');
    if (!result) return {error:1,message:'Result Object not fetched!'};
    if (!result.data) return {error:1,message:'Result Data not fetched!'};
    if (!result.data.users) return {error:1,message:'Users not fetched!'};
    try
    {
        var user=result.data.users.find((user)=> 
                        user.firstName==name 
                        && user.lastName==surname);
        if (user)
        {
            const isUserBoughtBeforeTicket=await Transaction.getBalance(EXECUTER_ADDRESS,10006);
            if (parseInt(isUserBoughtBeforeTicket.balance)==0)
            {
                // Send to Ticket Revelant Address
                const transactionResult=await Transaction.sendToken(EXECUTER_ADDRESS,1,10006);
                if (transactionResult.tx)
                {
                    // Inform to ticket organizator using with their service 
                    //for completed new ticket operation
                    await Tools.postData('https://ticketorganizatorservice.xyz/newTicket/',{tx:transactionResult.tx,address:EXECUTER_ADDRESS});
                    return {error:0,message:'Congratulations! Ticket has been transferred to your wallet Operation Number:'+transactionResult.tx};
                }
                else
                return {error:1,message:'There was an error while processing!'};
            }
            else
                return {error:1,message:'You have already a ticket! '+
                                         'You cannot buy twice this address!'};
        }
        else
            return {error:1,message:'User not found for this ticket organization!'};
    }
    catch(e)
    {
        return {error:1,message:e.message};
    }
}

async function getAllUsers()
{
        let result=await Tools.getData('https://dummyjson.com/users');
        return result;

}
PreviousTime Based Inheritor ExampleNextA sample about token vesting

Last updated 1 year ago

➿
🔔
🍁