Punica Suite is Ontology's dApp development framework and has (almost) everything you need to start developing your Ontology based dApp.
Punica provides developers with a complete set of open-source development tools for dApp development, will allow developers to develop their projects quickly and easily for use on the Ontology blockchain. Please see below for a list of open-source tools and resources to help get you started.
There are a few technical requirements before we start. Please install the following:
pip install punica
npm install punica-ts -g
or
python setup.py install
Note: If you are using Python, please ensure you have Python v3.7 or above installed.
To use most Punica commands, you need to run them against an existing Punica project. So the first step is to create a Punica project.
punicaUsage: punica [OPTIONS] COMMAND [ARGS]...Options:-p, --project PATH Specify a punica project directory.-v, --version Show the version and exit.-h, --help Show this message and exit.Commands:compile Compile the specified contracts to avm and...deploy Deploys the specified contracts to specified...init Initialize new and empty Ontology DApp...invoke Invoke the function list in default-config or...node Ontology Blockchain private net in test mode.scpm Smart contract package manager,support...smartx Ontology smart contract IDE,SmartX...test Unit test with specified smart contractunbox Download a Punica Box, a pre-built Ontology...wallet Manager your ontid, account, asset.
You can create a bare Punica project with no smart contracts included, use punica init
command.
Once this operation is completed, you'll now have a project structure with the following items:
contracts/
: Directory for Ontology smart contracts.src/
: Directory for DApp source file.test/
: Directory for test files for testing your application and contracts.wallet/
: Directory for save Ontology wallet file.You can create an empty Punica project with no smart contracts using the init
command.
punica init
Once this operation has completed, you will have a project structure with the following items:
contracts/
: Directory for Ontology smart contracts.src/
: Directory for DApp source file(s).test/
: Directory for test files to test your application and contracts.wallet/
: Directory for saved Ontology wallet file.For more usage information, you can use punica init --help
punica init --helpUsage: punica init [OPTIONS]Initialize new and empty Ontology DApp project.Options:-h, --help Show this message and exit.
Note: If you are not running punica-cli in the root directory of your project, you need to use the -p
or --project
option to specify your DApp project path.
For those just getting started, you can use Punica Boxes which are example dApps/project templates to help you.
We will be using the Tutorialtoken-box through-out this tutorial which creates an OEP4 token that can be transferred between accounts.
Create a new directory for your Punica project:
mkdir tutorialtokencd tutorialtoken
Download ("unbox") the Tutorialtoken-box Box:
punica unbox tutorialtoken
For more usage information, you can use punica unbox --help
punica unbox --helpUsage: punica unbox [OPTIONS] BOX_NAMEDownload a Punica Box, a pre-built Ontology DApp project.Options:-h, --help Show this message and exit.
The Tutorialtoken-box contains a file called `punica-config.json' in the project root directory which defauls to the Ontology Testnet. You can alter the DefaultNet setting in this file to set which network Punica-Cli will use.
Example punica-config.json:
Note:
punica unbox <box-name>
command to download any of the other Punica Boxes.-p
or --project
option to specify your DApp project's path.You can use the following command to compile your Ontology smart contracts:
punica compile
If everything goes smoothly, you can find the avm
and abi
file in contracts/build
folder.
contacts├─build│ contract.avm│ contract_abi.json
For more usage, you can use punica compile --help
command.
$ punica compile --helpUsage: punica compile [OPTIONS] CONTRACT_NAMECompile the specified contracts to avm and abi file.Options:--contracts TEXT Compile specified contracts files in contracts dir.--local BOOLEAN Use local compiler.-h, --help Show this message and exit.
After you compile the smart contract ensure you have sufficient ONG in the account that will be paying for the deployment (see next step) or else deployment will fail. The address for the Tutorialtoken-box is ANH5bHrrt111XwNEnuPZj6u95Dd6u7G4D6
Note: If you are not running punica-cli in the root directory of your project, you need to use the -p
or --project
option to specify your DApp project path.
To deploy the Tutotialtoken-box smart contract to the selected network, run the following:
punica deploy
A simple deployment process looks like this:
Using network 'testNet'.Running deployment: oep4.avmDeploying...... 0x0131c56b6a00527ac46a51527ac46a00c3044e616d659c6409006593096c7566Deploy to: 0xf9f47e6a80482eb1c8831789f46dbc5a4f606222Deploy successful to network...... 0xc08a440a7f93cc7229fee15b55455fac51ec15153753303bd252c710547ecb62Enjoy your contract:)
For more usage information, you can use punica deploy --help
punica deploy --helpUsage: punica deploy [OPTIONS]Deploys the specified contracts to specified chain.Options:--network TEXT Specify which network the contract will be deployed.--avm TEXT Specify which avm file will be deployed.--wallet TEXT Specify which wallet file will be used.-h, --help Show this message and exit.
Notes:
-p
or --project
option to specify your DApp project path.avm
files exist in your contracts/build
directory, you need to use the --avm
option to specify which contract you want to deploy.If a multi-wallet file exist in your wallet
directory, you may need to use the --wallet
option to specify which wallet you want to use. If you do not specify a random wallet file in wallet
directory will be used.
To setup your smart contract you must run the punica invoke
command before invoking any specific functions.
punica invoke
Output:
Running invocation: oep4.jsonUsing network 'testNet'.Unlock default payer account...Unlock account: ANH5bHrrt111XwNEnuPZj6u95Dd6u7G4D6Please input account password:Unlock successful...Invoking Name...Invoke successful...... Invoke result: 546f6b656e4e616d65Invoking Symbol......
In the default-config.json
file of the Tutorialtoken-box is an 'invokeConfig' section that defines the functions of our smart contract. See example below:
"invokeConfig":
To see the list of available functions:
punica invoke list
Response when running `punica invoke list' on the Tutorialtoken-box
All Functions:InitNameSymbolDecimalTotalSupplyBalanceOfTransferTransferMultiAllowanceTransferFrom
For more usage information, you can use punica invoke --help
punica invoke --helpUsage: punica invoke [OPTIONS]Invoke the function list in punica-config.Options:--network TEXT Specify which network the contract will be deployed.--wallet TEXT Specify which wallet file will be used.--functions Text Specify which function will be used.-h, --help Show this message and exit.
Notes:
-p
or --project
option to specify your DApp project path.If a multi-wallet file exist in your wallet
directory, you may need to use the --wallet
option to specify which wallet you want to use. If you do not specify a random wallet file in wallet
directory will be used.
Shows the download link for Solo-chain, a pre-built Ontology private-net.
For more usage information, you can use `punica node --help'
punica node --helpUsage: punica node [OPTIONS]Ontology Blockchain private net in test mode. please download fromhttps://github.com/punicasuite/solo-chain/releasesOptions:-h, --help Show this message and exit.
The smart contract package manager allows you to download and publish punica boxes to the community repository.
punica scpmUsage: punica scpm [OPTIONS]smart contract package manager,support download and publish.Options:-h, --help Show this message and exit.
SmartX is Ontology's online smart contract IDE and debugger.
punica smartxPlease go to Smartx for debugging smart contracts:http://smartx.ont.io/#/
The test function allows you to run automated test against your smart contract using a test file.
For more usage information, you can use `punica test --help'
punica test -hUsage: punica test [OPTIONS] COMMAND [ARGS]...Unit test with specified smart contractOptions:--file TEXT Specify which test file will be used.-h, --help Show this message and exit.Commands:template generate test template file
Allows you to manage your wallet with functions such as adding, listing or deleting accounts or OntID's as well as transfering assets (ONT/ONG).
Example:
punica wallet account listAccount:ANH5bHrrt111XwNEnuPZj6u95Dd6u7G4D6AazEvfQPcQ2GEFFPLF1ZLwQ7K5jDn81hveAd4H6AB3iY7gBGNukgBLgLiB6p3v627gz1ARLvwmvJ38stT9MKD78YtpDak3MENZkoxF
For more usage information, you can use `punica wallet --help'
punica wallet --helpUsage: punica wallet [OPTIONS] COMMAND [ARGS]...Manager your asset, ontid, account.Options:-h, --help Show this message and exit.Commands:account Manage your account.asset Manage your asset, transfer, balance,...ontid Manage your ont_id, list or add.