ZPK
Join the Auction
Getting StartedChevronSmart Contract Example

Hello World Smart Contract on ZKP Testnet

Welcome to your first smart contract deployment on the ZKP Testnet! This simple example will help you understand how to create, deploy, and interact with smart contracts on our blockchain

Hello World Smart Contract on ZKP Testnet

What We're Building

We'll create a "Hello World" smart contract that:

icon

Stores a greeting message

icon

Allows anyone to read the message

icon

Lets the owner update the message

icon

Keeps track of how many times it's been updated

icon

Stores a greeting message

icon

Allows anyone to read the message

icon

Lets the owner update the message

icon

Keeps track of how many times it's been updated

This is perfect for learning the basics without any complexity!

The Smart Contract Code

Here's our simple smart contract written in Solidity

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

contract HelloWorld {
    // State variables
    string public greeting;
    address public owner;
    uint256 public updateCount;

    // Event to log when greeting is updated
    event GreetingUpdated(string newGreeting, uint256 updateNumber);

    // Constructor - runs when contract is deployed
    constructor() {
        greeting = "Hello, ZKP World!";
        owner = msg.sender;
        updateCount = 0;
    }

    // Function to update the greeting (only owner can do this)
    function updateGreeting(string memory _newGreeting) public {
        require(msg.sender == owner, "Only owner can update greeting");
        greeting = _newGreeting;
        updateCount++;
        emit GreetingUpdated(_newGreeting, updateCount);
    }

    // Function to read the greeting (anyone can call this)
    function getGreeting() public view returns (string memory) {
        return greeting;
    }

    // Function to get contract info
    function getContractInfo() public view returns (string memory, address, uint256) {
        return (greeting, owner, updateCount);
    }
}

Step-by-Step Deployment

Prerequisites

icon

MetaMask wallet connected to ZKP testnet

icon

Some ZKP coins from our faucet

icon

Basic understanding of how to use Remix IDE

icon

MetaMask wallet connected to ZKP testnet

icon

Some ZKP coins from our faucet

icon

Basic understanding of how to use Remix IDE

Step 1: Open Remix IDE

icon

This is a free, web‑based development environment

icon

No downloads or installations needed!

icon

This is a free, web‑based development environment

icon

No downloads or installations needed!

Step 2: Create Your Contract File

icon

In the file explorer (left panel), click the “+” button

icon

Name your file HelloWorld.sol

icon

Copy and paste the smart contract code above

icon

The file will automatically save

icon

In the file explorer (left panel), click the “+” button

icon

Name your file HelloWorld.sol

icon

Copy and paste the smart contract code above

icon

The file will automatically save

Step 3: Compile Your Contract

icon

Click on the "Solidity Compiler" tab (second icon on the left)

icon

Make sure the compiler version is set to 0.8.0 or higher

icon

Click "Compile HelloWorld.sol"

icon

You should see a green checkmark when compilation succeeds

icon

Click on the "Solidity Compiler" tab (second icon on the left)

icon

Make sure the compiler version is set to 0.8.0 or higher

icon

Click "Compile HelloWorld.sol"

icon

You should see a green checkmark when compilation succeeds

Step 4: Connect to ZKP Testnet

icon

Make sure MetaMask is connected to ZKP testnet

icon

Click on the "Deploy & Run Transactions" tab (third icon on the left)

icon

In the "Environment" dropdown, select "Injected Web3"

icon

MetaMask should connect automatically

icon

Confirm you see "ZKP Testnet" in the network indicator

icon

Make sure MetaMask is connected to ZKP testnet

icon

Click on the "Deploy & Run Transactions" tab (third icon on the left)

icon

In the "Environment" dropdown, select "Injected Web3"

icon

MetaMask should connect automatically

icon

Confirm you see "ZKP Testnet" in the network indicator

Step 5: Deploy Your Contract

icon

Make sure "HelloWorld" is selected in the contract dropdown

icon

Click the orange "Deploy" button

icon

MetaMask will popup asking you to confirm the transaction

icon

Confirm the transaction (it will cost a small amount of ZKP for gas)

icon

Wait for the transaction to be confirmed (usually takes a few seconds)

icon

Make sure "HelloWorld" is selected in the contract dropdown

icon

Click the orange "Deploy" button

icon

MetaMask will popup asking you to confirm the transaction

icon

Confirm the transaction (it will cost a small amount of ZKP for gas)

icon

Wait for the transaction to be confirmed (usually takes a few seconds)

Interact with your contract

Step 6: Interact with Your Contract

Once deployed, you’ll see your contract in the "Deployed Contracts" section

Reading Data (Free Operations)
Check

Click greeting to see the current greeting

Check

Click owner to see who owns the contract

Check

Click updateCount to see how many times it's been updated

Check

Click getGreeting to read the greeting via function call

Check

Click getContractInfo to get all info at once

Writing Data (Costs Gas)
Check

Enter a new message in the updateGreeting field

Check

Click the button to update the greeting

Check

Confirm the transaction in MetaMask

Check

Check that updateCount increased by 1

Understanding What Happened

Contract Deployment

When you deployed the contract:

icon

The constructor ran and set the initial greeting

icon

Your wallet address became the owner

icon

The contract was given a unique address on the blockchain

icon

The code is now permanently stored and publicly verifiable

icon

The constructor ran and set the initial greeting

icon

Your wallet address became the owner

icon

The contract was given a unique address on the blockchain

icon

The code is now permanently stored and publicly verifiable

Reading vs Writing

icon

Reading data (view functions) is free and instant

icon

Writing data (state changes) costs gas and requires confirmation

icon

Only the owner can update the greeting (access control)

icon

Anyone can read the greeting (public accessibility)

icon

Reading data (view functions) is free and instant

icon

Writing data (state changes) costs gas and requires confirmation

icon

Only the owner can update the greeting (access control)

icon

Anyone can read the greeting (public accessibility)

Events and Logs

When you update the greeting, the contract emits an event that:

icon

Gets permanently recorded on the blockchain

icon

Can be searched and filtered

icon

Provides a history of all updates

icon

Gets permanently recorded on the blockchain

icon

Can be searched and filtered

icon

Provides a history of all updates

Verifying Your Contract

On the Block Explorer

icon

Go to Explorer (Available soon)

icon

Search for your contract address

icon

View the transaction history

icon

See the contract code and interactions

icon

Go to Explorer (Available soon)

icon

Search for your contract address

icon

View the transaction history

icon

See the contract code and interactions

Contract Address

Your contract now has a permanent address like: 0x7424d35Cc6634C0532925a3b8D421B3e8A51F7E6d Anyone can:

icon

Interact with your contract using this address

icon

View its code and transaction history

icon

Call its public functions

icon

Interact with your contract using this address

icon

View its code and transaction history

icon

Call its public functions

Common Issues and Solutions

"Transaction Failed"

Problem

Problem

Not enough ZKP for gas fees

Solution

Solution

Get more coins from the faucet

Problem

Problem

Not enough ZKP for gas fees

Solution

Solution

Get more coins from the faucet

"Only Owner Can Update"

Problem

Problem

Trying to update from wrong wallet

Solution

Solution

Use the same wallet that deployed the contract

Problem

Problem

Trying to update from wrong wallet

Solution

Solution

Use the same wallet that deployed the contract

"Contract Not Found"

Problem

Problem

Wrong network or address

Solution

Solution

Double-check you're on ZKP testnet

Problem

Problem

Wrong network or address

Solution

Solution

Double-check you're on ZKP testnet

"Compilation Error"

Problem

Problem

Syntax error in the code

Solution

Solution

Copy the exact code from this example

Problem

Problem

Syntax error in the code

Solution

Solution

Copy the exact code from this example

Next Steps

Experiment with Your Contract

icon

Try updating the greeting with different messages

icon

Check how the updateCount increases

icon

Share your contract address with friends so they can read your greeting

icon

Try updating the greeting with different messages

icon

Check how the updateCount increases

icon

Share your contract address with friends so they can read your greeting

Learn More

icon

Modify the code to add new features

icon

Try creating a contract that stores multiple messages

icon

Experiment with different data types and functions

icon

Modify the code to add new features

icon

Try creating a contract that stores multiple messages

icon

Experiment with different data types and functions

Advanced Features

icon

Add more complex logic

icon

Implement multiple owner functionality

icon

Create contracts that interact with each other

icon

Explore ZKP's privacy features

icon

Add more complex logic

icon

Implement multiple owner functionality

icon

Create contracts that interact with each other

icon

Explore ZKP's privacy features

Code Explanation

State Variables

solidity
string public greeting;      // Stores the greeting message
address public owner;        // Stores the contract owner's address
uint256 public updateCount;  // Counts how many times greeting was updated

Constructor

solidity
constructor() {
    greeting = "Hello, ZKP World!";  // Set initial greeting
    owner = msg.sender;               // Set deployer as owner
    updateCount = 0;                  // Initialize counter
}

Access Control

solidity
require(msg.sender == owner, "Only owner can update greeting");

This line ensures only the person who deployed the contract can update it.

Events

solidity
event GreetingUpdated(string newGreeting, uint256 updateNumber);
emit GreetingUpdated(_newGreeting, updateCount);

Events create a permanent log of important actions.

Why This Matters

This simple example demonstrates:

Why This Matters

Check

Decentralization

No central authority controls your contract

Check

Transparency

All code and transactions are publicly visible

Check

Permanence

Once deployed, your contract lives forever on the blockchain

Check

Accessibility

Anyone can interact with your contract from anywhere

Check

Low Cost

Deployment and interaction costs are minimal

Congratulations

Congratulations!

You've successfully deployed your first smart contract on the ZKP blockchain! You now understand:

Check

How to write basic Solidity code

Check

How to compile and deploy contracts

Check

How to interact with deployed contracts

Check

The difference between reading and writing blockchain data

This is just the beginning. Smart contracts can power everything from simple games to complex financial systems. The ZKP testnet is your playground to experiment and learn without any risk.

Ready to build something more complex? Join our community and start exploring the endless possibilities of decentralized applications!

The Proof Behind Champions

Those who compete at the edge of human precision now back the technology that defines digital truth.

Buy Zero Knowledge Proof Coin Before It Hits the Market

Join the Auction
Own the Proof