Your First Smart Contract
Cyclone Smart Contracts: As Easy as 1-2-3
Start the Local Node
Clone the repository: Git CYCLONE https://github.com/GRANDblockchain/cyclone_release
Navigate to the project directory: cd cycloneNode
Start Docker Compose: docker compose up
Open CyPlay developer tool in your browser: http://localhost:3432/
Note: Alternative http://164.68.127.226:3432/ (You can use this public node if you don't want to install the node on your local machine).
Writing Your First Contract
A contract in Cyclone default VM is a set of JavaScript functions. To call these functions, you need to perform a transaction with the following message format:
callContract(<contract address>, <function name>, <function parameters>)
Parameters are separated by commas.
Our first contract will consist of a single function. It will accept a user's name as a parameter and save the string Hello <user name>
to the blockchain.
function sayHello(user) {
addCustomField('Hello ', user);
}
Our contract is ready. We used the predefined function addCustomField
of the default virtual machine, which takes two parameters: key
and value
, and saves them to the blockchain.
You can find a list of all built-in functions of the virtual machine by clicking the [Show Docs] button in CyPlay.
Testing the Contract
To test the contract, add the function call after its declaration:
function sayHello(user) {
addCustomField('Hello ', user);
}
sayHello('Satoshi');
Click the [Simulate] button. CyPlay will simulate the execution of the contract, and the data will not be written to the blockchain. The simulation results will be displayed. If there are any errors, they will be shown in the [E] field.
Deploying the Contract
If there are no errors, remove the function call sayHello('Satoshi')
and click the [Save] button. CyPlay will display a link with the address of the saved smart contract.
When you follow this link, you will see the result of your contract deployment transaction. If the block
field shows <nil>
, it means the transaction has not yet been included in a block. Wait 2-7 seconds and refresh the page. The C
object will display the address of your contract in the Cyclone Chain network.
Calling the Contract
Now let's call your contract. In СyPlay, enter:
callContract('ba4515e9dafb25f4fa965c40efdd9cae13dd4de5e96211a22021b3953361c7e9', 'sayHello', 'Nakamoto')
Click button [Simulate] to simulate the contract execution. If you want to execute it on the blockchain, click [Deploy].
Last updated