Scenario
Scenario commands allows executing all modifiable actions by implementer. Before use the scenarios, please be sure than you informed and and fee results. All Scenario commands are below and also explained on their section.
This endpoint returns information about a scenario created on the PIRI network. It takes the scenario address as a parameter, and this address also serves as a PIRI address.
A scenario also functions as a wallet. The scenario itself can have its own assets, and transfers of these assets can be made within the scenario based on integrated code.
Before creating a scenario, it's advisable to refer to the relevant guidelines in the following links:
https://piriscan.com/scenarios
https://whitepaper.pirichain.com/v1.0.3/pirichain-smart-scenario/pirichain-smart-scenario
Looking at the information returned by this endpoint, we have:
countOfExecution: Stores how many times this scenario has been executed.
address: The scenario's address.
ownerAddress: Information about the address that created the scenario.
name: The descriptive name of the scenario.
description: Contains descriptions related to the scenario.
tags: Tags created for the scenario.
createDate: The creation date of the scenario.
validated: Information about whether the scenario has been validated by other nodes.
scenarioText: The JavaScript code associated with the scenario.
byteCode: Bytecode equivalent of the scenarioText.
The list of functions related to the scenario can be extracted and read from scenarioText using the JSON.parse method.
Since the scenarios and their structures may vary from system to system, the security of scenarios should be carefully reviewed, rigorously tested, and then published.
Scenario Address | It is aslo a PIRI Address
OK
POST /getScenario HTTP/1.1
Host: core.pirichain.com
Content-Type: application/x-www-form-urlencoded
Accept: */*
Content-Length: 18
"address='text'"
OK
{
"error": 0,
"data": {
"countOfExecution": 170,
"_id": "64d7a7b5599032859f7ab571",
"address": "PRTMPKQF8LJMEYgn3KcnW6CcHYnZ4q2whLFDfgg4pX4",
"ownerAddress": "PRTMRKWZ56v4D8mV1oj813bqTgdfUm9J4woVTDMpGxF",
"name": "final deposit and withdraw swap scenario",
"description": "final deposit and withdraw swap scenario",
"tags": "final deposit and withdraw swap scenario",
"createdDate": "2023-08-12T15:39:33.321Z",
"validated": 0,
"scenarioText": "//####PIRICHAIN Smart Scenario v.1.0########\n// PiriChain Smart Scenario Code Blocks Area \n\n // All Functions must be return promise non-blocking async block or await prefix delimitier.. \n\nasync function depositLiqudity(ratio)\n{....",
"__v": 0
},
"byteCode": "002f002..."
}
This endpoint allows you to create a Smart Scenario within the PIRI network. PIRIchain Smart Scenarios are permanent pieces of code that automate tasks within the system. They are immutable and cannot be modified.
To code Smart Scenarios, you can use either JavaScript or TypeScript. For more detailed explanations and information about PIRIchain Smart Scenarios, you can access the following links:
https://piriscan.com/scenarios
https://whitepaper.pirichain.com/v1.0.3/pirichain-smart-scenario/pirichain-smart-scenario
Owner PIRI Address
Private Key
To Execution Restriction by Owner
false
Scenario Codes in Javascript | Typescript
Scenario name
Scenario description
Scenario Tags
OK
POST /createScenario HTTP/1.1
Host: core.pirichain.com
Content-Type: application/x-www-form-urlencoded
Accept: */*
Content-Length: 133
"address='text'&privateKey='text'&executeOnlyByMe=false&scenarioText='text'&name='text'&description='text'&tags='text'"
OK
{
"countOfExecution": 0,
"_id": "12345678901234567890abcd",
"address": "PRTMExampleScenarioAddress1234567890",
"ownerAddress": "PRTMExampleOwnerAddress1234567890abcd",
"name": "Example Scenario",
"description": "This is an example scenario description.",
"tags": "['Example', 'Demo', 'Test']",
"createdDate": "2024-08-22T10:00:00.000Z",
"validated": 0,
"scenarioText": "async function init(param1, param2, param3) { return 'example'; }",
"__v": 0
}
This endpoint lists the smart scenarios on the PIRI network associated with the PIRI address provided as a parameter (ownerAddress parameter). The schema returned with "getScenario" is now presented as an array within the "data" this time.
PIRI Address where scenarios will be listed
OK
POST /listMyScenarios HTTP/1.1
Host: core.pirichain.com
Content-Type: application/x-www-form-urlencoded
Accept: */*
Content-Length: 23
"ownerAddress='text'"
OK
{
"error": 0,
"data": [
{
"countOfExecution": 0,
"_id": "632b10e81ca0c3ae24ebe5b7",
"address": "PRTMPGC6pVU8sZFWK9CS5ZrnCzCBUfDEdrPfYMKoRAS",
"ownerAddress": "PRTMR5pDravSYmAdohUNSoGoEgwyEg2mG8xbWuAfb47",
"name": "Test",
"description": "This is test description.",
"tags": "['Business', 'Development', 'Schedule', 'RSS Feed', 'Lab Study']",
"createdDate": "2022-09-21T13:26:00.454Z",
"validated": 0,
"scenarioText": "002f002f002...",
"__v": 0
}
]
}
This endpoint lists all smart scenarios in the PIRI network. It takes "skip" and "limit" as parameters. The use of these parameters is recommended for pagination.
Number of records to skip for pagination
Maximum number of records to return
OK
POST /listScenarios HTTP/1.1
Host: core.pirichain.com
Content-Type: application/x-www-form-urlencoded
Accept: */*
Content-Length: 20
"skip=1&limit=1"
OK
{
"error": 0,
"data": [
{
"countOfExecution": 0,
"_id": "632b10e81ca0c3ae24ebe5b7",
"address": "PRTMPGC6pVU8sZFWK9CS5ZrnCzCBUfDEdrPfYMKoRAS",
"ownerAddress": "PRTMR5pDravSYmAdohUNSoGoEgwyEg2mG8xbWuAfb47",
"name": "Test",
"description": "This is test description.",
"tags": "['Business', 'Development', 'Schedule', 'RSS Feed', 'Lab Study']",
"createdDate": "2022-09-21T13:26:00.454Z",
"validated": 0,
"scenarioText": "002f002f00230...",
"__v": 0
}
],
"count": 1
}
Execute a read-only call to a scenario method without making changes to the blockchain
The address of the scenario to call
Public key of the caller
Address of the caller
Method name to call in the scenario
Parameters to pass to the method
OK
POST /callScenario HTTP/1.1
Host: core.pirichain.com
Content-Type: application/x-www-form-urlencoded
Accept: */*
Content-Length: 94
"scenarioAddress='text'&publicKey='text'&address='text'&method='text'¶ms='text'"
OK
{
"error": 0,
"data": {
"result": "success",
"gasUsed": 1500,
"executionTime": 25
}
}
This endpoint allows the execution of an intelligent scenario within the PIRI network. The result to be returned after the execution of the scenario may differ from the template specified below. This is because each scenario may have its own output structure.
After running the scenario, it may not produce any output or may generate parameters for another scenario. Therefore, it is beneficial to have information about the scenario before running it. These include:
Who created the scenario?
Description of the scenario
List of functions associated with the scenario
Descriptions of the expected outputs at the end of the scenario
Whether malicious code is used within the scenario
What information the scenario carries
Whether the scenario was created by a Domain Verified PIRI Address (DVPA).
Scenario Address | It is aslo a PIRI Address
Executer PIRI Address
Private Key
The method to be run in the scenario
Parameters | e.g.: ["value1", "value2", ...]
Amount to send Token to Scenario Address
Asset ID to send Token to Scenario Address
OK
POST /executeScenario HTTP/1.1
Host: core.pirichain.com
Content-Type: application/x-www-form-urlencoded
Accept: */*
Content-Length: 125
"scenarioAddress='text'&address='text'&privateKey='text'&method='text'¶ms=['text']&amount=1&assetID='text'"
OK
{
"error": 0,
"returnedData": [
"Example Result"
]
}
This endpoint is built on the principle of executing before saving to the PIRI network for a scenario. Unlike the "executeScenario" endpoint, it focuses on temporarily running specified functions within the provided code.
In other words:
It is common for scenario authors to execute it.
It may be used to execute changes on a previously saved scenario.
It can be used to test the security of a scenario.
While alternative usage methods not covered in these examples may exist, it is advisable to refer to the "executeScenario" section for considerations before testing a scenario.
Scenario Text | Javascript or Typescript Code
Executer PIRI Address
Private Key
The method to be run in the scenario
Parameters | e.g.: ["value1", "value2", ...]
OK
POST /previewScenario HTTP/1.1
Host: core.pirichain.com
Content-Type: application/x-www-form-urlencoded
Accept: */*
Content-Length: 94
"scenarioText='text'&address='text'&privateKey='text'&method='text'¶ms=['text']"
OK
{
"error": 0,
"returnedData": [
"AHMET"
]
}
Was this helpful?