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
  • Custom ERC20 token code
  • Deploy and interact with the contract
  • Deploy the smart contract
  • Interact with the ERC20 contract
  • Takeaways
  • Next steps
  1. Start Coding 🚀
  2. Quickstart

Create an ERC20 token

In this tutorial you'll build and deploy an ERC20 token to Validium Devnet

PreviousDeploy your first contractNextTooling

Last updated 7 months ago


This tutorial shows you how to deploy and interact with an ERC20 token on Validium Devnet.

This is what you're going to do:

Build an ERC20 token smart contract with additional custom logic

Deploy the smart contract to the Validium Devnet using Remix or Atlas.

Prerequisites

  1. Before you start, make sure that .

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

Custom ERC20 token code

ERC20 tokens are a standard for fungible tokens, which can be traded and represent a fixed value. You’ve used ERC20 tokens if you’ve transacted with USDC, DAI, USDT, LINK or UNI.

The ERC20 token we’re going to deploy will allow users to mint and burn tokens. The entire smart contract code is as follows:

// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";

contract TestToken is ERC20, Ownable, ERC20Burnable {
    constructor(string memory name, string memory symbol) ERC20(name, symbol) {
        _mint(msg.sender, 100 * 10 ** decimals());
    }

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}

Validium is EVM compatible, so you can use existing popular libraries like OpenZeppelin.

The most important features are:

  • Ownable : this extension sets the deployer account as owner of the smart contract. It also introduces the onlyOwner modifier that restricts the execution of certain functions to the owner of the contract.

  • ERC20Burnable: this extension adds the burn and burnFrom functions to the smart contract. These functions destroy tokens from a given account.

  • constructor: called on deployment, the constructor will assign the given name and symbol to the token and mint 100 units of it to the account that deployed the contract.

  • mint : this function creates new token units to a given account. It uses the onlyOwner modifier so it can only be called from the owner account.

Deploy and interact with the contract

To complete this tutorial you'll use either Atlas or Remix. Select your preferred tool:

AtlasRemix

Deploy the smart contract

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.

You can see the contract in the Atlas code editor. In the right sidebar, make sure the selected network is “Validium Devnet“ and click on "Deploy" to trigger the smart contract compilation and deployment.

Once compiled sign the transaction with your wallet and wait until its processed. You’ll see the contract in the “Deployed contracts” section.

Interact with the ERC20 contract

In the scripts folder you can find the mint-token.ts script containing the following code:

import { ethers } from "hardhat";

// Address of the ERC20 token contract
const TOKEN_CONTRACT_ADDRESS = "";
// Wallet that will receive tokens
const RECEIVER_WALLET = "";
// Amount of tokens to mint in ETH format, e.g. 1.23
const TOKEN_AMOUNT = "";

async function main() {
  const Token = await ethers.getContractFactory("TestToken");
  const tokenContract = Token.attach(TOKEN_CONTRACT_ADDRESS);

  console.log("Minting tokens...");

  const tx = await tokenContract.mint(
    RECEIVER_WALLET,
    ethers.parseEther(TOKEN_AMOUNT),
  );
  await tx.wait();

  console.log("Success!");
  console.log(
    `The account ${RECEIVER_WALLET} now has ${await tokenContract.balanceOf(
      RECEIVER_WALLET,
    )} tokens`,
  );
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

This scripts uses ethers to interact with the contract we’ve just deployed.

Existing libraries like ethers , viem and web3.js can be used to interact with smart contracts deployed on Validium.

Fill the following variables:

  • TOKEN_CONTRACT_ADDRESS: the contract address of the ERC20 token we just deployed.

  • RECEIVER_WALLET: address of a different account that will receive new tokens.

  • TOKEN_AMOUNT: the amount of tokens we’ll send to the account.

With the mint-token.ts file open in the Atlas editor, click on the “Deploy” button to run the script and see the output in the terminal.

Takeaways

  • Validium is EVM compatible and supports existing smart contract libraries like OpenZeppelin

  • Use popular libraries like ethers , viem, or web3.js to interact with smart contracts deployed on Validium.

The ERC20 token code is provided “as is” without any express or implied warranties.

  • The regulatory regime governing digital assets is still developing and is unclear in many jurisdictions.

  • ERC20 tokens may possess unique legal, tax, and market risks, so it is up to you to determine which, if any, laws apply to your deployment of ERC20 tokens.

  • The developers and publishers of this software disclaim any liability for any legal issues that may arise from its use.

Next steps

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

To confirm the account has received the tokens, visit the and search the receiver wallet address. You’ll see the new token balance in the assets table:

Continue learning about .

Open smart contract in Atlas
Learn more about Validium custom compilers
Validium Devnet explorer
paymasters and paying transaction fees with this ERC20 token
one of the faucets
you’ve configured the Validium Devnet in your wallet
ERC20 interact script in Atlas
ERC20 interact script in Atlas
ERC20 tokens in account balance