Tutorial

1. Precondition

Connect your wallet and sign up through MetaMask.

Web3OJ uses the Etheruem Sepolia test network as its blockchain network.

If you don't have Sepolia ETH, receive it from the Faucets. Alchemy Sepolia PoW Faucet

Alchemy Sign-up - Referal Link

 

2. Build the development environment

You need to build a local development environment to solve the problem.

Build a development environment through the Truffle or Hardhat framework.

node version

  • In hardhat, node version >= 12.0 is supported, but version 16 is recommended.

 

Build a development environment using the web3oj-sol repo

$ git clone https://github.com/web3oj/web3oj-sol.git

 

Build your own Hardhat development environment

$ mkdir web3oj-sol $ cd web3oj-sol $npx hardhat 888 888 888 888 888 888 888 888 888 888 888 888 888 888 888 8888888888 8888b. 888d888 .d88888 888888b. 8888b. 888888 888 888 "88b 888P" d88" 888 888 "88b "88b 888 888 888 .d888888 888 888 888 888 888 .d888888 888 888 888 888 888 888 Y88b 888 888 888 888 888 Y88b. 888 888"Y888888 888"Y88888 888 888"Y888888"Y888 👷 Welcome to Hardhat v2.9.2 👷‍ ? What do you want to do? … Create a basic sample project ❯ Create an advanced sample project Create an advanced sample project that uses TypeScript Create an empty hardhat.config.js Quit

 

Add sepolia network to hardhat.config.js

  • Sign up for [Alchemy] (https://alchemy.com/?r=2db6304f61f6b4e3) and create a project to get the Goerli API URL
// hardhat.config.js ... module.exports = { solidity: "0.8.4", networks: { // add sepolia sepolia: { url: process.env.SEPOLIA_URL || "https://eth-sepolia.g.alchemy.com/v2/...", // Put your Goerli API URL here accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [], }, }, gasReporter: { enabled: process.env.REPORT_GAS !== undefined, currency: "USD", }, etherscan: { apiKey: process.env.ETHERSCAN_API_KEY, }, };
  • You can set process.env.PRIVATE_KEY by creating an .env file in the root and putting it as follows.

    PRIVATE_KEY=0x1234567890asdfghjklqwertyuiop12345678....

 

Install openzepplin library

$ npm i @openzeppelin/contracts

 

Example) Solving addition problems

  1. Click Problem > Plus > Get Problem Instance.

  2. Copy the problem area and save it as contracts/PlusCalculator.sol. Copy the sample area and save it as contracts/MyPlusCalculator.sol.

  3. After completing the plus function in MyPlusCalculator.sol.

  4. Create and run scripts/plusCalculatorSol.js.

    produce

    // scripts/plusCalculatorSol.js const hre = require('hardhat'); let web3OJ; async function calculatorSol() { const [addr1] = await ethers.getSigners(); const MyPlusCalculator = await ethers.getContractFactory('MyPlusCalculator'); const myPlusCalculator = await MyPlusCalculator.connect(addr1).deploy(); await myPlusCalculator.deployed(); const instance = '0x000...000'; // Put the problem contract instance address here const PlusCalculatorProblem = await ethers.getContractFactory('PlusCalculatorProblem'); const plusCalculatorProblem = await PlusCalculatorProblem.attach(instance); await plusCalculatorProblem.setPlusCalculator(myPlusCalculator.address); } async function main() { calculatorSol(); } main().catch((error) => { console.error(error); process.exitCode = 1; });

    Execution

    $ npx hardhat --network sepolia run scripts/plusCalculatorSol.js
  5. Click Submit to finish solving the problem.

 

Contact

  • web3oj@gmail.com