Deploy using Validium CLI

Deploy a smart contract to Validium using the validium-cli in under 5 minutes


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 named Counter.

  • Deploy the smart contract to the Validium Testnet.

  • Interact with the contract using scripts.

Prerequisites

  1. Before you start, make sure that you’ve configured the Validium Testnet in your wallet.

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

validium-cli

Syntax:

npx validium-cli create <project-name>

Create Validium Project

  1. Use the command below to create a project

npx validium-cli create my-project
  1. Move to the just created project:

  1. Create a .env file and add these environment variables:

Add your account wallet private key here using which you want to deploy and interact with your contract. Also, you will need the Infura API key with the Holesky network enabled (the Underlying Ethereum network).

Review the Smart Contract

Review the contract inside contracts folder:

The Solidity smart contract contains four functions:

  • increment increases the value of the count state by 1 and emits the CountUpdated event.

  • decrement decreases the value of the count state by 1 and emits the CountUpdated event.

  • addToCount adds a value _value to the count state and emits the CountUpdated event.

  • getCount returns the current value of the count state.

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 Smart Contract

  1. Use this command to compile the smart contract:

It will compile and generate an artifacts folder named artifacts-zk . Logs:

It shows: Successfully compiled 2 Solidity files, becuase in the contracts folder we have two contracts, Counter.sol and MessageBoard.sol, here we are taking the example of Counter.sol only.

  1. Deploy to Validium Testnet:

syntax:

If you want to create your own script to deploy the compiled smart contract then add your <script-file> path after the command.

It will ask to select the contract to deploy from the list of 'compiled contracts'.

Select Counter.sol as we are working with this contract now. I will again prompt to enter the constructor arguments (in the smart contract we have none), so simply return empty.

This will deploy the compiled contract to the Validium Testnet.

Logs:

Piece of cake right? 🎊

Check the Contract in Validium Block Explorer

Use the contract address from the deployment logs to see the deployed contract on the Validium Block Explorer or use the link from the logs directly.

Deployed contract on Validium Block Explorer

You can also move to the Events tab and see the Greet event emitted through the constructor as a result of deployment:

Events tab showing the Greet Event value in Text format

Interact with the Deployed Contract

  1. Go to interact.ts file inside deploy folder:

syntax:

If you want to create your own script to interact with the deployed smart contract then add your <script-file> path after the command.

It will ask to select the contract to deploy from the list of 'compiled contracts'.

Select Counter.sol as we are working with this contract for now. I will prompt to enter the deployed contract address (copy from the deployments logs, it can also be found inside the deployments-zk folder). After providing the deployed contract address, it wil prompt to ask Select an action .

Select Call a view/pure function (read-only), it will list the available functions which can be executed under this selection, then select getCount to view the initial state of the count . After this call it will again prompt to ask Select an action .

This time select Call a function (state-changing) , it will list the available functions which can be executed. Select addToCount and provide any value (say 5).

After execution, again select Call a view/pure function (read-only) and call getCount .

Tada! 🎉 State updated!

Try this a couple of times more and then check the transactions in Validium Block Explorer:

Three transactions which was triggered from the interact command

Takeaways

  • validium-cli: This CLI tool streamlines deployment and facilitates seamless interaction with the Validium Network.

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

Next steps

  • Follow the same above steps to deploy your contract, changes can be made to interact.ts file and use your methods from the contract.

Last updated