Deploy using Quickstart Repository

Deploy a smart contract to Validium using the Quickstart Repository 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.

Quickstart Repository

Clone and Setup

  1. Clone this repo to get started with a pre-configured template quickly:

git clone https://github.com/Validium-Chain/Deploy-on-Validium.git
  1. Move to just the cloned folder and install dependencies:

cd Deploy-on-Validium
npm install
  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 three 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.

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

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

Update the following:

  • contractArtifactName (check generated artifacts-zk folder, usually the same as the contract file name)

  • constructorArguments (if providing any arguments to the constructor)

  1. Deploy to Validium Testnet:

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:

Update the following:

  • CONTRACT_ADDRESS (copy the contract address from the deployment logs and paste it here)

  • CONTRACT_NAME (contract artifact name from afticats-zk folder)

Run the interact script:

The interact script above triggers three transactions (two increment and one decrement) and one fetch (getCount) to the deployed contract. It also listens to the CountUpdated event when emitted.

Logs:

Check the transactions in Validium Block Explorer as well:

Three transactions which was triggered from the interact.ts script

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.

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