This tutorial will guide you through the process of creating a smart contract, deploying it to your private-net, testing and finally deploying it to the Ontology Mainnet.
The steps used will be:
The following tools will be needed:
Cyano wallet - an Ontology Google Chrome extension wallet
Create a new project in the language of your choice and use one of the templates (we will be using Arith) to work with if you don't have your own smart contract.
Compile your smart contract but do not deploy it yet.
Solo-chain is a pre-built Ontology private-net which includes a number of tools to interact with and monitor the network.
Download and install Solo-chain and verify it is working as expected. You can do this by checking that blocks are being generated and/or initiating a transaction.
Please make note of the IP address shown in the dashboard for later use.
Cyano wallet is a Google Chrome extension that is integrated with SmartX and allows developers to deploy/invoke smart contracts either on a private-net or the Ontology mainnet.
Install Cyano wallet and click on the settings cog in the top right hand corner of the first screen.
Change the network to Private-Net and put the IP address shown in the solo-chain interface in Cyano (typically 127.0.0.1).
Once Cyano is successfully connected to your private-net, the connection icon in the bottom right hand side of the screen will show a connected icon (as above).
Next, import the private key of the main address from your solo-chain into Cyano.
Finally, initiate a transaction and claim your ONG which will be used to pay for transaction fees during deployment/invocation.
Once you are satisfied with your smart contract, you can use SmartX to deploy it to your private-net. SmartX will interact with Cyano wallet in order to deploy and pay the transaction fee(s).
Select Deploy in SmartX and enter the appropriate details in the information fields (Name, Author, etc). Once this has been done, select deploy.
Cyano wallet will be launched and the smart contract deploy screen will be shown. Ensure the details are correct and select confirm.
Enter your Cyano wallet password to deploy your smart contract.
You can verify the smart contract has been deployed correctly by clicking the Smart Contract icon in solo-chain which will show you the contract hash and information you entered in SmartX.
The next step is to invoke your smart contract which is done in SmartX by selecting Run and selecting any methods (if applicable). In this example we are using the 'Arith' template so we will be using the add method to add two numbers together.
Once you click on Run, Cyano wallet will prompt you to invoke the smart contract which can be done by clicking confirm and entering your password.
The results of the invocation will be displayed in the log window of SmartX.
You can also use solo-chain to check the invoke function by selecting the Transactions tab and looking for a transaction type of Invoke.
More detailed information is available by clicking on the Detail link.
Once you have completed the above steps, you may wish to deploy your smart contract to the Ontology Mainnet for general purpose use.
To do this, in Cyano select the settings cog in the top right hand corner.
Change to network to Main-Net and click Save.
Ensure you have a Main-net wallet setup in Cyano with sufficient gas to deploy the contract before proceeding.
Finally, return to SmartX and follow the same process as you did in the Deploy smart contract in SmartX section ensuring that Cyano shows it is connected to Main-net.
Your smart contract will now be deployed to the Ontology Main-net and you can invoke it as you did in the Invoke smartcontract in SmartX section.