pen-to-squareGetting Started Guide

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

Prerequisites

Before you begin, please ensure you have the following basic knowledge and tools:

  • Basic blockchain knowledge: Familiarity 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 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 websitearrow-up-right.

    • 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

      Select "Create a basic sample project" and follow the prompts to complete initialization.

  3. Install MetaMask

Configure the WSCChain network

Name
Value

Network name

WSC Chain Mainnet

Description

WSC Chain mainnet

RPC endpoint

Chain ID

20180422

Currency symbol

WSC

Add the WSCChain mainnet in MetaMask:

  1. Open MetaMask and click the "Network" dropdown menu.

  2. Select "Add Network" > "Add a network manually."

  3. Enter the configuration information above and save.

Step 2: Obtain WSC tokens on mainnet

Deploying and testing smart contracts on the WSCChain mainnet requires WSC tokens. You can bridge them in 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.soland enter the following code:

Configure Hardhat

  1. Open hardhat.config.jsand add the WSCChain testnet configuration:

    • Replace YOUR_PRIVATE_KEY with your MetaMask private key (exported from "Account Details"; do not share it publicly).

  2. Make sure to install the necessary Hardhat plugins:

Compile the smart contract

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

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

Step 4: Deploy to the WSCChain mainnet

Write the deployment script

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

  2. Deploy the contract to the WSCChain mainnet:

    • After successful deployment, the terminal will output the contract address, for example:

  3. Enter the contract address in the WSCChain mainnet block explorer (https://scan.onwsc.com/arrow-up-right) to verify whether the deployment was successful.

Step 5: Interact with the smart contract

Test contract functionality

  1. Test in the Hardhat console:

  2. Enter the following commands to interact with the contract:

    • 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 through a webpage:

  1. Initialize a frontend project:

  2. Create index.html and app.js, example code is as follows:

Step 6: Connect to a WSCChain mainnet node

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

Use the public RPC

Last updated