Getting 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
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 -vIf you prefer yarn, you can use
npm install -g yarnto install it.
Install Truffle or Hardhat WSCChain supports mainstream Ethereum development frameworks. Here we use Hardhat as an example:
Install Hardhat globally:
npm install -g hardhatCreate a new Hardhat project:
npx hardhatSelect "Create a basic sample project" and follow the prompts to complete initialization.
Install MetaMask
Download and install the MetaMask browser extension:MetaMask official website.
Create or import a wallet account for subsequent testnet interactions.
Configure the WSCChain network
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
Block explorer
Add the WSCChain mainnet in MetaMask:
Open MetaMask and click the "Network" dropdown menu.
Select "Add Network" > "Add a network manually."
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
In the Hardhat project directory, go to the
contractsfolder.Create the file
SimpleStorage.soland enter the following code:
Configure Hardhat
Open
hardhat.config.jsand add the WSCChain testnet configuration:Replace
YOUR_PRIVATE_KEYwith your MetaMask private key (exported from "Account Details"; do not share it publicly).
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
In the
scriptsfolder, createdeploy.js:Deploy the contract to the WSCChain mainnet:
After successful deployment, the terminal will output the contract address, for example:
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 contract functionality
Test in the Hardhat console:
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:
Initialize a frontend project:
Create
index.htmlandapp.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
Mainnet RPC:https://rpc.onwsc.com
Use this RPC URL directly in Hardhat or other tools to connect to the network.
Last updated