# Deploy your first contract

***

This tutorial shows you how to deploy and interact with a smart contract on Validium in less than 5 minutes. It will help you get familiar with the Validium smart contract development and deployment process using different tools.

In this section you will learn how to:

Build a smart contract to exchange messages with Zeek.

Deploy the smart contract to the Validium Testnet.

Interact with the contract from your browser using Remix or Atlas.

### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

1. Before you start, make sure that you’ve configured the [Validium Testnet in your wallet](https://validium.gitbook.io/docs/connect-to-validium#add-validium-to-your-metamask-wallet).
2. Have at least 0.5 Validium Testnet VLDM. If you need more, use one of the [faucets](https://testnet.faucet.validium.network/).

### Review the smart contract code <a href="#review-the-smart-contract-code" id="review-the-smart-contract-code"></a>

The smart contract will store messages from users and emit events with replies from Zeek. The entire code is as follows:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract ZeekMessages {
    string[] private messages;

    // Event to acknowledge a new message
    event MessageReceived(string);

    constructor() {
        // Zeek initializes the contract with a welcome message
        emit MessageReceived("Zeek welcomes you to Validium!");
    }

    function sendMessage(string memory _message) public {
        messages.push(_message);

        // Acknowledge the message receipt with Zeek's reply
        emit MessageReceived("ZK is the endgame - Message received!");
    }

    // Function to count the total messages sent to Zeek
    function getTotalMessages() public view returns (uint) {
        return messages.length;
    }

    // Function to return the last message sent to Zeek
    function getLastMessage() public view returns (string memory) {
        require(messages.length > 0, "No messages sent to Zeek yet!");
        return messages[messages.length - 1];
    }
}
```

The Solidity smart contract contains two functions:

* `sendMessage` stores the messages sent by users in the `messages` state variable.
* `getTotalMessages` returns the number of messages stored in the smart contract.
* `getLastMessage` returns the last message sent.

Validium is EVM compatible. You can write smart contracts with Solidity or Vyper and use existing popular libraries like OpenZeppelin, just like on Ethereum.

### Compile and deploy the contract <a href="#compile-and-deploy-the-contract" id="compile-and-deploy-the-contract"></a>

To compile and deploy the contract you can use either Atlas or Remix:

AtlasRemix

Atlas is a browser-based IDE with an integrated AI assistant that allows you to write, test and deploy smart contracts directly from your browser. Click the button below to open the project in Atlas.

[Open smart contract in Atlas](https://app.atlaszk.com/templates/33EAJkwrTKFaDJiEuy9Om?chainId=300\&openFile=/contracts/ZeekSecretMessages.sol)

#### Compile and deploy the contract <a href="#compile-and-deploy-the-contract" id="compile-and-deploy-the-contract"></a>

Enter a name for the project and you will see the contract in the Atlas code editor. On the right side, make sure the selected network is “Validium Testnet“ and click on **“Deploy”** to trigger the smart contract compilation and deployment.

![Contract in Atlas](https://915971626-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbHkZ9halV79ZnIlLd4df%2Fuploads%2FKujrENi1ii46aXTzaMYj%2F1.png?alt=media\&token=346627d7-4839-4fc1-b630-520010cc8cff)

Behind the scenes, Atlas is using the Validium custom solidity compiler (named `zksolc` ) to generate ZKEVM compatible bytecode. Learn more about Validium custom compilers.

Once compiled sign the transaction with your wallet and wait until it's processed. You’ll see the contract in the “Deployed contracts” section. Congratulations, you’ve deployed your first smart contract to Validium Testnet!

#### Interact with the contract <a href="#interact-with-the-contract" id="interact-with-the-contract"></a>

Below the contract name you can find its deployment address. The “Live Contract State” section displays the smart contract balance and the value returned by the `getTotalMessages` function.

![Contract deployed](https://915971626-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbHkZ9halV79ZnIlLd4df%2Fuploads%2FAczKg7gnSuRHMRmwomla%2F2.png?alt=media\&token=fb4b47f7-1548-4e65-808f-c5e04c45d42d)

The “Write Functions” section contains the form to interact with the `sendMessage` function. Write a message, click the “Run” button and confirm the transaction in your wallet. You’ll see that the `getTotalMessages` is updated to `1` and `getLastMessage` returns the message you just sent. That means our contract is storing the messages as expected! But how can you see the replies from Zeek?

### Check the contract in explorer <a href="#check-the-contract-in-explorer" id="check-the-contract-in-explorer"></a>

Copy the smart contract address from Atlas/Remix and search it via the Validium Testnet explorer. You’ll see the contract has a transaction from the message you just sent.

![Contract in Validium explorer](https://915971626-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbHkZ9halV79ZnIlLd4df%2Fuploads%2FLkOMnjL1pSuPaONstc3G%2F3.png?alt=media\&token=bbc442f4-a940-4c82-87e3-e12a3829bb30)

The status will be “Processed” on Validium and “Sending” on Ethereum. [Learn more about the transaction lifecycle on Validium ](https://validium.gitbook.io/docs/concepts/transaction-lifecycle).

In the “Contract” tab you’ll see the contract source code as Atlas and Remix automatically verified the contract for us. When a smart contract is verified in a block explorer, it means that the source code of the contract has been published and matched to the compiled version on the blockchain enhancing transparency, as users can review the contract’s source code to understand its functions and intentions.

Finally in the “Events” tab, you’ll see the replies from Zeek as these are emitted as events in our smart contract.

![Contract events in Validium explorer](https://915971626-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbHkZ9halV79ZnIlLd4df%2Fuploads%2FAq2ZEZ7xKRLiirVx8l4v%2F4.png?alt=media\&token=60610207-4f3a-440a-9204-0b81400902b4)

ZK is the endgame ✌️

### Takeaways <a href="#takeaways" id="takeaways"></a>

* **EVM-compatibility**: Validium is EVM-compatible and you can write smart contracts in Solidity or Vyper as in Ethereum.
* **Custom compilers**: smart contracts deployed to Validium must be compiled with the customs compilers: `zksolc` for Solidity and `zkvyper` for Vyper.
* **Browser-based IDEs**: Existing tools like Atlas and Remix use Validium custom compilers under the hood.

### Next steps <a href="#next-steps" id="next-steps"></a>

* Continue learning by [deploying an ERC20 token to Validium](https://validium.gitbook.io/docs/start-coding/quickstart/create-an-erc20-token).
* Join the Validium developer community in Discord where you can ask any questions about this tutorial in the `#dev-quickstart` channel.
