VIA Protocol
  • Getting Started
    • Introduction
  • Technical Specs
    • Architecture Overview
    • Core Functionalities
      • Block Generation
      • Proof Generation
      • Proof Verification
      • Block Finality
    • Transaction Flows Overview
      • L2 Transactions
      • Deposits
      • Withdrawals
    • Inscription Standard
    • Verifier Network
  • User Guide
    • Bridge BTC between Bitcoin and VIA
    • Get VIA Testnet BTC
    • Run VIA Verifier Node
  • Developer Docs
    • Quickstart
    • Tooling
    • 🛰️ RPC Documentation
    • Connect to VIA Network
  • Future Research
    • System Constraints and Design Trade-offs
    • Trust-minimized BTC Bridge
  • FAQs & Troubleshooting
    • FAQs
    • Contact & Support
Powered by GitBook
On this page
  • Prerequisites
  • Setting Up the Example Project
  • Configuring Hardhat for VIA Network
  • Writing & Compiling the Smart Contract
  • Deploying the Contract to VIA Network
  • Interact with the CrowdfundingCampaign contract
  1. Developer Docs

Quickstart

Welcome to VIA developer documentation!

PreviousRun VIA Verifier NodeNextTooling

Last updated 1 month ago

VIA Network is a fork of ZKsync Era, inheriting its core technology and developer tooling. This means all ZKsync-compatible tools work seamlessly on VIA with minimal configuration changes. This documentation mirrors ZKsync's Hardhat setup but tailored for VIA Network.

Prerequisites

Before proceeding, ensure you have the following installed:

  • (v18+ recommended),

  • or npm,

  • A wallet with testnet tokens (for gas fees), you can bridge BTC to VIA chain using the ,

  • Basic knowledge of Solidity and Hardhat.

Setting Up the Example Project

Clone the via-playground project and install dependencies:

git clone https://github.com/vianetwork/via-core.git
cd via-core/via-playground
yarn install

Configuring Hardhat for VIA Network

The hardhat.config.ts file contains the network configuration. Ensure it includes the VIA Network RPC endpoint and your wallet's private key (for deployment).

module.exports = {
  defaultNetwork: 'via-testnet',
  solidity: "0.8.27",
  networks: {
    via-testnet: {
      url: "https://via.testnet.viablockchain.dev" // VIA testnet RPC endpoint
      chainId: 25223, // Via testnet chainId
      accounts: [process.env.PRIVATE_KEY],
    },
  },
};

Note: Store private keys in .env (use dotenv package for security).

Writing & Compiling the Smart Contract

The contracts/ directory contains example contracts (e.g., CrowdfundingCampaign.sol).

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

contract CrowdfundingCampaign {
    address public owner;
    uint256 private fundingGoal;
    uint256 private totalFundsRaised;
    mapping(address => uint256) private contributions;

    event ContributionReceived(address contributor, uint256 amount);
    event GoalReached(uint256 totalFundsRaised);

    constructor(uint256 _fundingGoal) {
        owner = msg.sender;
        fundingGoal = _fundingGoal;
    }

    function contribute() public payable {
        require(msg.value > 0, "Contribution must be greater than 0");
        contributions[msg.sender] += msg.value;
        totalFundsRaised += msg.value;

        emit ContributionReceived(msg.sender, msg.value);

        if (totalFundsRaised >= fundingGoal) {
            emit GoalReached(totalFundsRaised);
        }
    }

    function withdrawFunds() public {
        require(msg.sender == owner, "Only the owner can withdraw funds");
        require(totalFundsRaised >= fundingGoal, "Funding goal not reached");

        uint256 amount = address(this).balance;
        totalFundsRaised = 0;

        (bool success, ) = payable(owner).call{value: amount}("");
        require(success, "Transfer failed.");
    }

    function getTotalFundsRaised() public view returns (uint256) {
        return totalFundsRaised;
    }

    function getFundingGoal() public view returns (uint256) {
        return fundingGoal;
    }
}

Compile the contract

npx hardhat compile

Deploying the Contract to VIA Network

Deploy the CrowdfundingCampaign using the following command:

npx hardhat deploy --amount 100

The amount flag is the initial amount deposited in the campaign.

Expected Output: CrowdfundingCampaigndeployed to: 0x123...abc

Interact with the CrowdfundingCampaign contract

Let's now create some transactions to interact with the deployed contract

# Contribute to the Campaign
npx hardhat contribute --amount 10

# Get crowdfunding stats
npx hardhat stats

# The user withdraws funds from the crowdfunding
npx hardhat withdraw

Happy Building on VIA! 🚀

Node.js
Yarn
bridge UI