Getting Started Guide

Welcome to the WSCChain developer journey! This guide will help you quickly get started with the WSCChain platform, from setting up the development environment to deploying your first smart contract and connecting to the WSCChain mainnet. This chapter is aimed at developers who are new to WSCChain and is intended to provide clear steps and practical examples to ensure you can start building quickly.

Prerequisites

Before you begin, make sure you have the following basic knowledge and tools:

  • Basic blockchain knowledge: Be familiar with the basic concepts of smart contracts, blockchain transactions, and the Ethereum Virtual Machine (EVM).

  • Development tools:

    • Node.js(recommended v16 or higher): Used to run JavaScript and install dependencies.

    • npm or yarn: Package managers used to install project dependencies.

    • Code editor: Visual Studio Code or similar tools are recommended.

  • Wallet: Install MetaMask or another EVM-compatible wallet to manage accounts and testnet tokens.

  • Terminal skills: Basic command-line operation skills.

If you are already familiar with Ethereum development, WSCChain's full EVM compatibility will make your migration process very smooth.

Step 1: Set up the development environment

Install required tools

  1. Install Node.js and npm

    • Download and install the latest version of Node.js (which includes npm):Node.js official website.

    • Verify installation:

      node -v
      npm -v
    • If you prefer yarn, you can use npm install -g yarn to install it.

  2. Install Truffle or Hardhat WSCChain supports mainstream Ethereum development frameworks. Here we use Hardhat as an example:

    • Install Hardhat globally:

      npm install -g hardhat
    • Create a new Hardhat project:

      npx hardhat

      Choose “Create a basic sample project” and follow the prompts to complete initialization.

  3. Install MetaMask

    • Download and install the MetaMask browser extension:MetaMask official website.

    • Create or import a wallet account for subsequent testnet interactions.

Configure JuChain network

Name
Value

Network Name

WSC Chain Mainnet

Description

WSC Chain Mainnet

RPC Endpoint

https://rpc.onwsc.com wss://rpc.onwsc.com/ws

Chain ID

20180422

Currency Symbol

WSC

Add WSCChain mainnet to MetaMask:

  1. Open MetaMask and click the “Networks” dropdown menu.

  2. Select “Add Network” > “Add a network manually.”

  3. Enter the above configuration information and save.

Step 2: Obtain WSC tokens on the mainnet

Deploying and testing smart contracts on the WSCChain mainnet requires WSC tokens. You can bridge tokens yourself using a cross-chain bridge.

Step 3: Write your first smart contract

Below is a simple smart contract example for storing and reading data on WSCChain.

Create the smart contract

  1. In the Hardhat project directory, go to the contracts folder.

  2. Create the file SimpleStorage.sol, and enter the following code:

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;
    
    contract SimpleStorage {
        uint256 private storedValue;
    
        // Store a value
        function set(uint256 _value) public {
            storedValue = _value;
        }
    
        // Get the stored value
        function get() public view returns (uint256) {
            return storedValue;
        }
    }

Configure Hardhat

  1. Open hardhat.config.js, and add WSCChain testnet configuration:

    require("@nomicfoundation/hardhat-toolbox");
    
    module.exports = {
      solidity: "0.8.0",
      networks: {
        juchain_testnet: {
          url: "https://rpc.onwsc.com",
          chainId: 
          accounts: ["YOUR_PRIVATE_KEY"] // Replace with your private key (keep it secure)
        }
      }
    };
    • Replace YOUR_PRIVATE_KEY with your MetaMask private key (export from “Account Details”; do not share it publicly).

  2. Make sure to install the necessary Hardhat plugins:

    npm install --save-dev @nomicfoundation/hardhat-toolbox

Compile the smart contract

Run the following command in the terminal to compile the contract:

npx hardhat compile

After success, you will see the compilation results in the artifacts folder.

Step 4: Deploy to the WSCChain mainnet

Write a deployment script

  1. In the scripts folder, create deploy.js:

    const hre = require("hardhat");
    
    async function main() {
      const SimpleStorage = await hre.ethers.getContractFactory("SimpleStorage");
      const simpleStorage = await SimpleStorage.deploy();
    
      await simpleStorage.deployed();
      console.log("SimpleStorage deployed to:", simpleStorage.address);
    }
    
    main()
      .then(() => process.exit(0))
      .catch((error) => {
        console.error(error);
        process.exit(1);
      });
  2. Deploy the contract to the WSCChain mainnet:

    npx hardhat run scripts/deploy.js --network wscchain
    • After a successful deployment, the terminal will output the contract address, for example:

      SimpleStorage deployed to: 0x1234...abcd
  3. Enter the contract address in the WSCChain mainnet block explorer (https://scan.onwsc.com/) to verify whether the deployment was successful.

Step 5: Interact with the smart contract

Test the contract functionality

  1. Test in the Hardhat console:

    npx hardhat console --network wscchain
  2. Enter the following commands to interact with the contract:

    const SimpleStorage = await ethers.getContractFactory("SimpleStorage");
    const simpleStorage = await SimpleStorage.attach("0x1234...abcd"); // Replace with your contract address
    await simpleStorage.set(42);
    (await simpleStorage.get()).toString();
    • The output should be "42", indicating the contract is working properly.

Use ethers.js for frontend interaction (optional)

If you want to interact with the contract via a web page:

  1. Initialize a frontend project:

    npm init -y
    npm install ethers
  2. Create index.html and app.js, with example code as follows:

    import { ethers } from "ethers";
    
    const provider = new ethers.providers.Web3Provider(window.ethereum);
    await provider.send("eth_requestAccounts", []);
    const signer = provider.getSigner();
    const contractAddress = "0x1234...abcd"; // Replace with your contract address
    const abi = [ /* Copy the ABI from artifacts/SimpleStorage.json */ ];
    const contract = new ethers.Contract(contractAddress, abi, signer);
    
    // Set value
    await contract.set(100);
    // Get value
    const value = await contract.get();
    console.log("Stored value:", value.toString());

Step 6: Connect to WSCChain mainnet nodes

WSCChain provides free public RPC nodes so developers can develop and test without running their own nodes.

Use the public RPC

  • Mainnet RPC:https://testnet-rpc.juchain.org

  • Use this RPC URL directly in Hardhat or other tools to connect to the network.

Last updated