# 模擬考試題 **及格線:6題/10題** ## Solidity 基礎 **1. 列舉五種 Solidity 的型別並且寫出實際例子** **2. 寫出一 function 可接受 eth value 並且 return 自定義結果** **3. ERC20 合約部屬至 rinkeby,寫上部屬的合約地址** ## Solidity 進階 **1. 試寫出多簽錢包程式碼,調整同意比例(1/3)** **2. 實作 ERC20 質押某代幣,timelock(固定鎖倉期,自定義), reward (回饋該代幣)** ## Solidity 整合開發相關 **1. 試說明如何整合 VSCode, 以及 Remix 的開發環境** **2. 試寫出 contract auto verify 的 相關內容(npm install xxx, hardhat.config.js, npm hardhat xxx)** **3. 試寫出部屬 ERC721 合約並且先 mint 10 個 NFT 的 hardhat.js script** ## Solidity 資安相關 **標註程式碼第幾行可能有資安問題,並說明何種資安問題,並提出解法** ```=solidity // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; contract DepositContract { using SafeMath for uint256; mapping(address => uint256) public balance; function deposit() external payable { balance[msg.sender] += msg.value; } function withdraw(uint256 amount) external { require(balance[msg.sender] >= amount, "Account balance is not enough"); balance[msg.sender] -= amount; (bool success, ) = msg.sender.call{value: amount}(""); require(success, "Transfer failed."); } function withdrawAll() external { (bool success, ) = msg.sender.call{value: balance[msg.sender]}(""); require(success, "Transfer failed."); balance[msg.sender] = 0; } } ``` ## Solidity 節省 Gasfee 相關 **嘗試閱讀以下程式碼,如何寫出更節省Gas fee 的方法** ```=solidity ... ... address[] whitelistedAddresses; function isWhitelisted(address _user) public view returns (bool) { for (uint i = 0; i < whitelistedAddresses.length; i++) { if (whitelistedAddresses[i] == _user) { return true; } } return false; } ``` **完整程式碼** https://etherscan.io/address/0xae122962331c2b02f837b2aa501d3c5d903ed28a#code