The Latest Version of SmartX is Now Available! – OntologyNetwork
After opening the newly created Wasm contract project, the bytecode of the Wasm contract was shown in the area of contract editing. The bytecode in this part can be replaced.
Next step, it is time to deploy the Wasm contract. This step is no different to that of deploying a NeoVM contract. Fill the related information in the right deploy tool page, and click the deploy button, the Chrome plug-in wallet Cyano Wallet (which should be installed to the most updated version in advance) will be called, and users will be asked to fill in the wallet password. If there is enough ONG in Cyano Wallet, the Wasm contract will be deployed to Ontology network after a short period. You can click Apply ONG as shown on the below image to apply for ONG on TestNet.
After successful deployment, you will encounter the Run page of the contract. Here we can call the Wasm contract.
We need to enter the name of the function to be called add, add the parameters required for the function, select the correct type for the parameter, and enter the parameter value. The add function requires two data types of u128. The u128 in the contract corresponds to the Long type in SmartX, so the parameter type should be Long. Then choose either pre-execute or run button. The result of the contract execution will be displayed in the log area on the lower left-hand side. You only need to click on pre-execution, because data on the chain will not yet be updated, and the printed result in log area is hex encoding, which is used to decode.
Now that we have completed the deployment and invocation of Wasm contracts on SmartX, let’s dive into the call of hello and say functions. The hello function just returns the “hello world” string therefore no parameters need to be entered. Check the call screenshot as follows:
The method of say results in adding the prefix ”say” to in-parameters and return. Parameters of type & STR are required. Type & STR parameters in the contract correspond to type string on SmartX. The call example is as follows:
In this article, we have used an example to briefly introduce the main process of deploying and invoking a Wasm contract on SmartX. Note the following points:
Before use, the following preparation is required:
- You must open SmartX in the Chrome browser and install Ontology’s plug-in wallet: Cyano Wallet
- When deploying and calling, you must first confirm whether the Ontology network connected in Cyano Wallet is updated (currently the test network is supported with main network support coming soon)
- When deploying and calling, ensure your ONG balance is adequate to cover the commission for deploying and calling contracts.
Published at Sun, 15 Dec 2019 12:58:13 +0000
{flickr|100|campaign}
