OPNet-cli is a .NET Core CLI utility designed to streamline the creation, management, and deployment of OP20 contracts and others. It allows developers to initialize projects, create OP20 token contracts, and manage contract deployment through a simple command-line interface. The tool supports cross-platform environments and ensures that contract development is efficient and straightforward.
- .NET Core Framework version 8 Download here
-> There is no installer for now. <-
Clone the git repo.
- See the build.md file on how to build from the source code.
- Copy the files and folders generated by the build into a location of your choice, or use it from there.
or
Download a release and unzip to a foler of your choice.
- Open a shell (command prompt).
- Give the execute permission by executing the following command: chmod +x opnetcli
- When setting a parameter value that contains spaces, enclose the value in double quotation marks
""
. - Parameters marked with
*
are mandatory.
Create a generic OP20 contract project. This includes:
- Contract source files.
- Deployment files.
- Unit tests.
Parameters:
*contractname
: The name of the contract.contractpath
: The path where the contract files will be stored. If not specified, the current directory is used. (optional)
Example:
opnetcli createcontract -contractname:test -contractpath:c:/temp/contracts
Create a basic token project. This includes:
- Contract source files.
- Deployment files.
- Unit tests.
Parameters:
*contractname
: The name of the contract.contractpath
: The path where the contract files will be stored. (optional)*tokenname
: The name of the token.*tokensymbol
: The token symbol.*tokendecimals
: The number of decimals for the token.*tokenmaxsupply
: The maximum supply of the token.
Example:
opnetcli createtoken -contractname:TestToken -contractpath:c:/temp/contracts -tokenname:TestToken -tokensymbol:TSTTKN -tokendecimals:18 -tokenmaxsupply:10000000
Display the deployment steps.
To deploy a WebAssembly (WASM) contract using OPNet-cli, follow these steps. The WASM file to be deployed is located in the build folder of your contract.
Overview of Key Files:
config.ts
: Contains deployment configuration information such as the network provider, the network to deploy on, and the wallet's private key.deploy.ts
: Responsible for launching the deployment process.
Steps:
-
Navigate to the deploy folder:
- Open your terminal or command prompt.
- Change the directory to the deploy folder where the deployment scripts are located.
-
Configure the Deployment Settings:
- Open the
config.ts
file in a text editor. - Modify the following settings:
OPNET_PROVIDER
: Set this to the desired provider.NETWORK
: Set this to the appropriate network.PRIVATE_KEY
: Replace 'YOUR PRIVATE KEY HERE' with your actual wallet's private key.
- Save the
config.ts
file.
- Open the
-
Install Dependencies: Run the following command to install the necessary dependencies:
npm install
-
Build the Deployment Scripts: After installing dependencies, run the following command to build the deployment scripts:
gulp
-
Deploy the Contract: Change the directory back to the main folder of your contract, and deploy the contract:
node ./deploy/build/deploy.js
Important Warnings:
- Private Key Security: Do not leave your wallet private key in the
config.ts
file. After deploying the contract, remove your private key from this file. - Repository Security: Ensure the
config.ts
file is not pushed to any repository with your private key intact.
When you generate a contract project using OPNet-cli, a basic unit testing framework is created. This structure provides the initial framework for testing, but it requires manual updates to cover all contract functionality.
-
Basic Unit Test Structure:
- Placeholder test cases are generated. Manually expand them to cover all contract functionality.
- Unit tests are located in the
src/tests
folder. You will find a file named after your contract (e.g.,MyContract.ts
), where the tests are written.
-
Contract WASM File: Ensure the WASM file for your contract is placed in the
bytecode
folder in theunittests
directory. Unit tests require the compiled WASM file to validate contract behavior. -
Update
config.ts
: Theconfig.ts
file in thesrc/contracts
folder must be updated to set theNETWORK
field for the appropriate test network (e.g., testnet, mainnet). -
Implement the Contract Interface: In the
src/contracts
folder, manually code the file named after your contract to reflect the contract’s methods. This interface enables your unit tests to call contract methods.Implementation Steps:
- Create interfaces for all event classes and data classes in your smart contract.
- Implement decoders for all event and data classes.
- Create selector methods for all exposed methods in the contract.
- Implement method wrappers for all exposed contract methods.
-
Write Unit Tests:
- Use the initial unit test structure in
src/tests/MyContract.ts
to create comprehensive tests. - Refer to the assertion functions in
src/opnet/unit/Assert.ts
andsrc/opnet/unit/Assertion.ts
for validating test outcomes.
- Use the initial unit test structure in
Additional Information:
- More detailed documentation and examples will be published on the website.
- Continuously update your unit tests as the contract evolves to ensure thorough testing of new features.
This project is licensed under the MIT License. View the full license here.
This README provides all necessary details for developers to get started with OPNet-cli, create and deploy OP20 contracts, and manage unit testing for their smart contracts.