# Your First Smart Contract

### Start the Local Node

Clone the repository:\
Git CYCLONE <https://github.com/GRANDblockchain/cyclone_release>

1. Navigate to the project directory:\
   **cd cycloneNode**
2. Start Docker Compose:\
   **docker compose up**
3. Open CyPlay developer tool in your browser:\
   [**http://localhost:3432/**](http://localhost:3432/)                      &#x20;

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).

<figure><img src="https://3931730355-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frxbe1N9Il2WjzwVFQGsb%2Fuploads%2FVQwVAUUsou1jTnvBwGWJ%2Fimage.png?alt=media&#x26;token=5a6bf34f-217f-4742-8bc3-535ef60dfe6e" alt=""><figcaption><p>CyPlay (IDE Draft version) </p></figcaption></figure>

4. **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:

<mark style="color:purple;">`callContract(<contract address>, <function name>, <function parameters>)`</mark>

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 <mark style="color:purple;">`Hello <user name>`</mark> to the blockchain.

<mark style="color:purple;">`function sayHello(user) {`</mark>

&#x20;   <mark style="color:purple;">`addCustomField('Hello ', user);`</mark>

<mark style="color:purple;">`}`</mark>

Our contract is ready. We used the predefined function <mark style="color:purple;">`addCustomField`</mark> of the default virtual machine, which takes two parameters: <mark style="color:purple;">`key`</mark> and <mark style="color:purple;">`value`</mark>, 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.

<figure><img src="https://3931730355-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frxbe1N9Il2WjzwVFQGsb%2Fuploads%2F013AfPJMlTzO4cWwvmuE%2Fimage.png?alt=media&#x26;token=22360eea-7479-4e60-ba7a-47b57d528c22" alt=""><figcaption><p>CyPlay</p></figcaption></figure>

### Testing the Contract

To test the contract, add the function call after its declaration:

<mark style="color:purple;">`function sayHello(user) {`</mark>

&#x20;   <mark style="color:purple;">`addCustomField('Hello ', user);`</mark>

<mark style="color:purple;">`}`</mark>

<mark style="color:purple;">`sayHello('Satoshi');`</mark>

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.

<figure><img src="https://3931730355-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frxbe1N9Il2WjzwVFQGsb%2Fuploads%2Fnn1yUEYcCortebNX4ttH%2FTelegram_uC7uY8yhY2.png?alt=media&#x26;token=c9c913b0-9983-4e50-a42a-eb66e57b6a15" alt=""><figcaption><p>CyPlay</p></figcaption></figure>

### Deploying the Contract

If there are no errors, remove the function call <mark style="color:purple;">`sayHello('Satoshi')`</mark> and click the **\[Save]** button. CyPlay will display a link with the address of the saved smart contract.&#x20;

<figure><img src="https://3931730355-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frxbe1N9Il2WjzwVFQGsb%2Fuploads%2FhhD863kAftbDQuMLcqJv%2Fimage.png?alt=media&#x26;token=5bca2da5-6822-42a1-b115-6b6641597a06" alt=""><figcaption><p>CyPlay</p></figcaption></figure>

When you follow this link, you will see the result of your contract deployment transaction. If the <mark style="color:purple;">**`block`**</mark> field shows <mark style="color:purple;">**`<nil>`**</mark> , it means the transaction has not yet been included in a block. Wait 2-7 seconds and refresh the page. The <mark style="color:purple;">**`C`**</mark> object will display the address of your contract in the Cyclone Chain network.

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXd4y7PPV6U3T0hMhzqAcJt_l9KNJFTMDDu2kKHr2GRQT2PnrypWaAH7OcWt18CCvUjV2s-TSImHShItZi5vWFLr6SIOazHGahgFZoXoCjsGyu-LD6r_jPMKs8mzDf3FNtbPC2jC1hPqT3o_QjlcYYxWIdr-?key=ZlmVg45H9j-dx11oc361bg" alt=""><figcaption></figcaption></figure>

### Calling the Contract

Now let's call your contract. In СyPlay, enter:

<mark style="color:purple;">`callContract('ba4515e9dafb25f4fa965c40efdd9cae13dd4de5e96211a22021b3953361c7e9', 'sayHello', 'Nakamoto')`</mark>

Click button **\[Simulate]** to simulate the contract execution. If you want to execute it on the blockchain, click **\[Deploy].**
