Validium Docs
  • Overview
  • Connect to Validium
  • Start Coding 🚀
    • Quickstart
      • Overview
      • Deploy using Validium CLI
      • Deploy using Quickstart Repository
      • Deploy your first contract
      • Create an ERC20 token
  • Tooling
    • Block Explorers
    • Hardhat-Validium
      • Overview
      • Installation
      • Guides
        • Getting started
        • Migrating Hardhat project to Validium
        • Compiling non-inlinable libraries
      • Plugins
        • hardhat-zksync
        • hardhat-zksync-solc
        • hardhat-zksync-vyper
        • hardhat-zksync-deploy
        • hardhat-zksync-upgradable
        • hardhat-zksync-verify
        • hardhat-zksync-verify-vyper
        • hardhat-zksync-ethers
        • hardhat-zksync-node
        • Hardhat Community Plugins
    • Foundary
      • Overview
      • Installation
      • Getting Started
      • Migration Guide
        • Overview
        • Compilation
        • Deployment
        • Testing
  • Test and Debug
    • Getting Started
    • Docker L1 - L2 Nodes
    • In-Memory Node
    • Continuous Integration
    • Hardhat
    • Foundry
  • API Reference
    • Overview
    • Conventions
    • ZKs JSON-RPC API
    • Debug JSON-RPC API
    • Ethereum JSON-RPC API
    • PubSub JSON-RPC API
  • Concepts
    • Transaction Lifecycle
    • Blocks and Batches
    • Validium Network Fee Mechanism
    • Finality
    • System Upgrades
    • ZK Chains
    • Data Availability
      • Overview
      • Recreating L2 state from L1 pubdata
      • Validiums
    • Account Abstraction
    • L1 <-> L2 Communication
  • Components
    • Overview
    • Smart & System Contracts
      • Smart Contracts
      • System Contracts
    • Shared Bridges
    • Sequencer / Server
    • Validium Network EVM
      • Overview
      • Bootloader
      • Precompiles
      • Virtual Machine Specification
        • ZKsync Virtual Machine primer
        • VM Formal Specification
    • Prover
      • Overview
      • ZK Terminology
      • Running the Prover
      • Circuits
        • Overview
        • Circuit Testing
        • CodeDecommitter
        • DemuxLogQueue
        • ECRecover
        • KeccakRoundFunction
        • L1MessagesHasher
        • LogSorter
        • Main VM
        • RAMPermutation
        • Sha256RoundFunction
        • StorageApplication
        • Sorting and Deduplicating
          • Overview
          • SortDecommitments
          • StorageSorter
          • LogSorter
      • Boojum Gadgets
      • Boojum Function - `check_if_satisfied`
    • Compiler
      • Compiler Toolchain Overview
        • Compiler Toolchain Overview
        • Solidity Compiler
        • Vyper Compiler
        • LLVM Framework
      • Specification
        • Overview
        • Code Separation
        • System Contracts
        • Exception Handling
        • EVM Legacy Assembly Translator
        • Instructions
          • Instruction Reference
          • EVM
            • Native EVM Instructions
            • Arithmetic
            • Bitwise
            • Block
            • Call
            • Create
            • Environment
            • Logging
            • Logical
            • Memory
            • Return
            • Sha3
            • Stack
          • Extensions
            • Overview
            • Validium Network Extension Simulation (call)
            • Validium Network Extension Simulation (verbatim)
          • EVM Legacy Assembly
          • Yul
        • EraVM Binary Layout
    • Fee Withdrawer
    • Portal - Wallet + Bridge
    • Block Explorer
    • Transaction filtering
Powered by GitBook
On this page
  • Prerequisites
  • Review the smart contract code
  • Compile and deploy the contract
  • Check the contract in explorer
  • Takeaways
  • Next steps
  1. Start Coding 🚀
  2. Quickstart

Deploy your first contract

Deploy a smart contract to Validium from your browser using Remix or Atlas in under 5 minutes

PreviousDeploy using Quickstart RepositoryNextCreate an ERC20 token

Last updated 7 months ago


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

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

Prerequisites

  1. Before you start, make sure that you’ve configured the .

  2. Have at least 0.5 Validium Devnet VLDM. If you need more, use one of the .

Review the smart contract code

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

// 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

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.

Compile and deploy the contract

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 Devnet“ and click on “Deploy” to trigger the smart contract compilation and deployment.

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 Devnet!

Interact with the contract

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.

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

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

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.

ZK is the endgame ✌️

Takeaways

  • 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

  • Join the Validium developer community in Discord where you can ask any questions about this tutorial in the #dev-quickstart channel.

The status will be “Processed” on Validium and “Sending” on Ethereum. .

Continue learning by .

Open smart contract in Atlas
Learn more about the transaction lifecycle on Validium
deploying an ERC20 token to Validium
faucets
Validium Devnet in your wallet
Contract in Atlas
Contract deployed
Contract in Validium explorer
Contract events in Validium explorer