> For the complete documentation index, see [llms.txt](https://smartscenarios.pirichain.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://smartscenarios.pirichain.com/psce-functions/examples/asset-management-of-share-holders-using-with-psce.md).

# Asset Management Of Share Holders using with PSce

This scenario presents that 2 different share holders have been created at first stage. Then these people can sell their share holder percentage to other people.

```javascript
//####PIRICHAIN Smart Scenario v.1.0########
// PiriChain Smart Scenario Code Blocks Area 

 // All Functions must be return promise non-blocking async block or await prefix delimitier..  

const myProductName='Ferrari';
const myProductWorth=1000000;
const contractExplanation='This Product can be sold with shareholders how much they have. And All of Shareholders must accept before operations!';

async function initializeDeliverShareHolders()
{

    if (PSDATA["shareHolders"]==undefined)
    {
            PSDATA['totalPerson']=2;
            PSDATA["shareHolders"]=new Array();
            PSDATA["shareHolders"].push({name:'Alex',holderpercent:50,address:'PRTMRKWZ56v4D8mV1oj813bqTgdfUm9J4woVTDMpGxF'});
            PSDATA["shareHolders"].push({name:'Barbara',holderpercent:50,address:'PRTMPp6wo6zGAcStmhmBGQErnomzhFCoaTfLuXKTvo2'});
            await Map.saveMap(JSON.stringify(PSDATA));       
    }
    return PSDATA["shareHolders"];
}
async function getHoldersWithAuthorized()
{
        initializeDeliverShareHolders();
        
        if (PSDATA["shareHolders"].find(r=>r.address==EXECUTER_ADDRESS)!=undefined)
            return PSDATA;
        else
            return {error:1,message:'You dont have right to execute this scenario. You are not shareholder in this scenario!'};
}

async function sellYourShareHolder(acceptText,buyerName,buyerAddress,buyerHolderPercent)
{
    initializeDeliverShareHolders();

    if (acceptText!=='I accept to sell my holder')
            return {error:1,message:'You need to write for accepting your holder!'};

    if (buyerAddress===EXECUTER_ADDRESS)
        return {error:1,message:'You cannot transfer to your self!'};

    if (parseFloat(buyerHolderPercent)<=0 || isNaN(parseFloat(buyerHolderPercent)))
        return {error:1,message:'Percent is not true format!'};

    const myHolder=PSDATA["shareHolders"].find(r=>r.address===EXECUTER_ADDRESS);
    if (myHolder==undefined)
        return {error:1,message:'Your holder has not been found!'};

    if (myHolder.holderpercent<buyerHolderPercent)
        return {error:1,message:'Your Percent is not enough that you wanted to sell! Please decrease the holder to sell'};
    
    myHolder.holderpercent-=buyerHolderPercent;

    const isExistsHolder=PSDATA["shareHolders"].find(r=>r.address===buyerAddress);
    if (isExistsHolder==undefined)
    {
        PSDATA['totalPerson']+=1;
        PSDATA["shareHolders"].push({name:buyerName,holderpercent:buyerHolderPercent,address:buyerAddress});
    }
    else
    {
        isExistsHolder.holderpercent+=buyerHolderPercent;
    }
    
    return await Map.saveMap(JSON.stringify(PSDATA));       
}
async function getTotalPersonCount()
{
    initializeDeliverShareHolders();
    return PSDATA["totalPerson"];
}

async function listHolderTransactions(skip,limit)
{
    if (parseInt(skip)<0 || parseInt(limit)<=0)
    return {error:1,message:'Skip or Limit Param(s) are not true format!'};
    return await Transaction.listTransactions(EXECUTER_SCENARIOADDRESS,skip,limit);
}

async function getMyShareHolderPercentage()
{
    initializeDeliverShareHolders();
    const myHolder= PSDATA["shareHolders"].find(f=>f.address==EXECUTER_ADDRESS);
    if (myHolder===undefined)
        return 0;
    else
       return myHolder.holderpercent;
}

// Auto generated Withdraw Function.
// Please DO NOT Edit and Remove WithdrawAllAssetToOwnerWallet function!
/// Withdraw all amount of defined asset_ID to scenario owner address
async function WithdrawAllAssetToOwnerWallet(asset_ID)
{
    if (OWNER_ADDRESS!==EXECUTER_ADDRESS)
    return {error:1,data:'Only scenario owner can execute this method!'};
    if (asset_ID)
    {
        if (!isNaN(parseInt(asset_ID)))
        {
            const myBalanceObject=await Transaction.getBalance(EXECUTER_SCENARIOADDRESS,-1);
            let myBalance=parseFloat(myBalanceObject.balance);
            if (asset_ID===-1)
            {
                if (myBalance<1)
                    return {error:1,data:'Your Piri Coin is not enough to transfer!'};
                myBalance-=1; // Fee
                    return await Transaction.sendPIRI(OWNER_ADDRESS,myBalance);
            }
            else
            {
                if (myBalance<1)
                    return {error:1,data:'Your Piri Coin is not enough to transfer!'};             
                const myTokenBalanceObject=await Transaction.getBalance(EXECUTER_SCENARIOADDRESS,asset_ID);
                let myTokenBalance=parseFloat(myTokenBalanceObject.balance);
                if (myTokenBalance>0)
                    return await Transaction.sendToken(OWNER_ADDRESS,myTokenBalance,asset_ID);
                else
                return {error:1,data:'You dont have enough token balance!'};
            }

        }
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://smartscenarios.pirichain.com/psce-functions/examples/asset-management-of-share-holders-using-with-psce.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
