> For the complete documentation index, see [llms.txt](https://docs.swisstronik.com/swisstronik-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.swisstronik.com/swisstronik-docs/development/guides/contract-deployment-hardhat/3.-write-and-compile-the-smart-contract.md).

# 3. Write and compile the smart contract

{% hint style="info" %}
For the scope of this tutorial, we will publish a simple "Hello Swisstronik" smart contract with only 2 functions -one for writing to the blockchain and one for reading from the blockchain- with 1 state variable.
{% endhint %}

1. Go to the contracts folder and open the `.sol` file (smart contract).

We renamed it to `Hello_swtr.sol`

![](/files/HfC0kscdhHne59wuA72t)

2. Paste the smart contract into your `Hello_swtr.sol` file.

{% hint style="danger" %}
Currently, we only support Solidity compilers up to 0.8.19
{% endhint %}

```solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

//This contract is only intended for testing purposes

contract Swisstronik {
    string private message;

    /**
     * @dev Constructor is used to set the initial message for the contract
     * @param _message the message to associate with the message variable.
     */
    constructor(string memory _message) payable{
        message = _message;
    }

    /**
     * @dev setMessage() updates the stored message in the contract
     * @param _message the new message to replace the existing one
     */
    function setMessage(string memory _message) public {
        message = _message;
    }

    /**
     * @dev getMessage() retrieves the currently stored message in the contract
     * @return The message associated with the contract
     */
    function getMessage() public view returns(string memory){
        return message;
    }
}
```

3. Compile the contract

To compile the smart contract, run `npx hardhat compile`  in your terminal (if you are using VSCode, you can open a new terminal with *Ctrl + Shift + \`* )

After successful compilation:

1. You should get the message *Compiled 1 Solidity file successfully* in your terminal
2. A new *artifacts* folder should be created

<figure><img src="/files/H6QUsq4y3giOS2kqTw25" alt=""><figcaption></figcaption></figure>

Now you are ready to deploy this contract on Swisstronik! 🚀 <br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.swisstronik.com/swisstronik-docs/development/guides/contract-deployment-hardhat/3.-write-and-compile-the-smart-contract.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
