skka3134

skka3134

email
telegram

Game Company Interview Question

  1. It is said to be a chain game company, but the main focus of the interview is not on game-related topics, but on contracts.
  2. Interview: Simple self-introduction + projects on the resume + chainlink vrf principle + proxy contract principle.
  3. Chainlink vrf principle: Chainlink Oracle is a decentralized network with many oracle nodes in the network. Each oracle node can obtain data through its own channel and reach consensus on the obtained data in the decentralized network. The consensus method used is the median. The user passes a seed to the VRF contract, and the oracle VRF node uses its private key and seed to generate a random number and proof, which are returned to the VRF contract. The VRF contract verifies the legitimacy of the proof for the random number. If the verification passes, the random number will be returned to the user.
  4. Proxy contract principle: The user interacts with contract A, and contract A calls contract B. Contract A is a proxy contract, and contract B is a logic contract. If you want to upgrade, just change the content of contract A. However, during the upgrade process, the memory layout of contract A cannot be changed, only additions are allowed, deletions and modifications are not allowed.
    image
  5. Written test: Permission control + ownership transfer + modifier + event switch + IERC20 transfer + whitelist (bonus item) + eoa (bonus item)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;


import "ERC721";
import "IERC20";

contract Minter is ERC721 {
    address erc20;
    address owner;

    struct Project {
        uint256 eventId;
        uint256 timeEnd;
        address payAddress;
        uint256 price;
        bool state;
        uint8 amount;
    }
    Project[] projects;

    mapping(address => bool) public whiteBool;
    mapping(uint256 => Project) mintEvents;

    constructor() {
        owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "not owner");
        _;
    }

    function ownerTransfer(address owner_) onlyOwner {
        owner = owner_;
    }

    function stopEvent(uint256 k) onlyOwner {
        projects[k].state = false;
    }

    function white() onlyOwner {
        whiteBool[msg.sender] = true;
    }

    function setupEvent(
        uint256 eventId_,
        uint256 timeEnd,
        address payAddress_,
        uint256 price_,
        uint256 amount_
    ) onlyOwner {
        projects.push(
            Project(eventId_, timeEnd_, payAddress_, price_, amount_)
        );
    }

    function mint(uint256 k) public {
        require((projects[k].amount < 100, "exeed");
        require(projects[k].state = true, "not start");
        require(whiteBool[msg.sender] == true, "not white");
        require(msg.sender == tx.origin, "not eoa");
        projects[k].amount = amount + 1;
        IERC20(erc20).safeTransferFrom(
            msg.sender,
            projects[k].payAddress,
            projects[k].price * 1e18
        );
    }
}

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.