Quickstart
Welcome to Via Network developer documentation!
Quickstart
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:
- Node.js (v18+ recommended),
- Yarn or npm,
- A wallet with testnet tokens (for gas fees), you can bridge BTC to Via Network chain using the bridge UI,
- 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 installConfiguring 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(usedotenvpackage 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 compileDeploying the Contract to Via Network
Deploy the CrowdfundingCampaign using the following command:
npx hardhat deploy --amount 100The 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 withdrawHappy Building on Vianetwork**!** 🚀