kato9292929
@kato9292929

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Unreachable code. Unnamed return variable can remain unassigned.のエラーを解消したいです

解決したいこと

Unreachable code. Unnamed return variable can remain unassigned.のエラーを解消したいです

発生している問題・エラー

Unreachable code. Unnamed return variable can remain unassigned.

スクリーンショット 2022-01-14 5.42.46.png

該当するソースコード

ソースコードを入力

例)

pragma solidity >=0.7.0 <0.9.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./Base64.sol";

contract OnChainnft is ERC721Enumerable, Ownable {
  using Strings for uint256;

  string public baseExtension = ".json";
  uint256 public cost = 0.05 ether;
  uint256 public maxSupply = 10000;

  constructor() ERC721("On Chain NFT", "OCN") {}

  // public
  function mint(uint256 _mintAmount) public payable {
    uint256 supply = totalSupply();
    require(_mintAmount > 0);
    require(supply + _mintAmount <= maxSupply);

    if (msg.sender != owner()) {
      require(msg.value >= cost * _mintAmount);
    }

    for (uint256 i = 1; i <= _mintAmount; i++) {
      _safeMint(msg.sender, supply + i);
    }
  }

  function buildImage() public pure returns(string memory) {
    return Base64.encode(bytes(abi.encodePacked(
        '<svg version="1.0" xmlns="http://www.w3.org/2000/svg">',
        '<width="300.000000pt" height="300.000000pt" viewBox="0 0 300.000000 300.000000">',
        '<preserveAspectRatio="xMidYMid meet">',
        '<path d="M1015 1830 c6 -10 3 -12 -14 -7 -44 11 -53 -15 -51 -147 3 -166 3 -161 -16 -146 -27 23 -37 50 -23 66 8 10 8 14 0 14 -6 0 -11 -5 -11 -11 0 -5 -4 -7 -10 -4 -5 3 -10 14 -10 23 0 9 -14 30 -30 46 -17 16 -30 35 -30 42 0 7 -6 17 -14 21 -14 9 -41 54 -38 65 5 20 -37 33 -107 33 -122 0 -111 33 -111 -329 0 -213 3 -317 11 -321 6 -4 8 -14 5 -22 -4 -9 -2 -11 7 -6 6 4 44 6 83 4 53 -2 73 1 83 12 8 10 12 62 13 161 1 80 4 143 8 141 4 -2 15 -22 25 -45 10 -22 22 -40 27 -40 5 0 16 -16 24 -35 8 -19 18 -35 23 -35 5 0 12 -7 15 -16 3 -8 2 -12 -3 -9 -5 3 -13 1 -16 -5 -4 -6 -3 -10 2 -9 25 4 34 -3 29 -23 -3 -13 -3 -17 0 -10 11 24 25 12 20 -18 -2 -17 0 -28 5 -24 5 3 7 11 3 17 -5 10 5 0 45 -49 10 -12 176 -12 187 -1 9 9 4 641 -6 651 -5 5 -31 10 -59 12 -28 1 -56 6 -62 10 -8 5 -9 3 -4 -6z m-275 -39 c0 -6 50 -85 112 -178 61 -92 113 -176 116 -185 9 -38 17 -15 15 44 -2 35 -4 123 -5 196 l-3 132 80 0 80 0 -3 -312 -3 -313 -80 2 -80 2 -104 158 c-58 87 -113 176 -123 197 -17 39 -18 38 -14 -160 l4 -199 -78 0 -79 0 0 312 0 313 83 0 c45 0 82 -4 82 -9z"/>',
        '<path d="M1819 1824 c-8 -10 -15 -48 -17 -90 -3 -88 4 -95 93 -88 71 6 117 -2 94 -17 -12 -7 -12 -9 2 -9 13 0 16 -18 18 -116 1 -75 -2 -120 -9 -129 -7 -8 -8 -20 -4 -27 11 -18 14 -132 3 -138 -4 -3 -2 -18 5 -32 8 -15 11 -30 8 -34 -4 -4 -1 -4 7 1 7 4 47 7 88 7 85 -1 109 13 106 63 -6 78 -5 354 1 363 3 6 2 13 -3 16 -10 7 -9 25 2 43 8 13 121 13 134 0 11 -12 21 -8 43 15 29 31 29 139 0 168 -12 12 -26 18 -32 14 -12 -8 -423 -8 -484 0 -31 4 -45 1 -55 -10z m571 -90 l0 -72 -106 6 -106 5 4 -249 3 -249 -80 0 -80 0 3 190 c1 105 3 217 5 251 2 50 -1 60 -13 58 -8 -2 -56 -5 -106 -8 l-91 -5 -1 72 -1 72 285 0 284 0 0 -71z"/>',
        '<path d="M1292 1821 l-24 -6 -2 -322 -1 -323 25 -9 c32 -13 137 -13 160 -1 18 10 33 47 22 54 -4 2 -5 44 -2 93 l5 88 105 -2 c67 -2 113 1 128 9 21 11 23 17 20 82 -3 67 -20 110 -41 99 -20 -11 -67 -11 -67 -1 0 9 -3 9 -12 0 -7 -7 -38 -12 -70 -12 -64 0 -75 10 -64 54 6 24 6 24 133 22 161 -3 163 -2 156 97 -3 40 -11 75 -17 79 -13 9 -419 7 -454 -1z m448 -86 l0 -70 -150 3 -150 3 0 -60 0 -61 133 0 132 0 0 -67 0 -68 -134 4 -134 3 5 -123 6 -124 -82 0 -81 0 0 315 0 315 228 0 227 0 0 -70z"/>',
        '<path d="M1708 1623 c7 -3 16 -2 19 1 4 3 -2 6 -13 5 -11 0 -14 -3 -6 -6z"/>',
        '</svg>'
    )));

     return string(abi.encodePacked(
        'data:application/json;base64,', Base64.encode(bytes(abi.encodePacked(
            '{"name": "OnChainTest',
            '", "description": "First test',
            '", "image": "data:image/svg+xml;base64,',
            buildImage(),
            '"}'
        )))
    ));
    }

  function walletOfOwner(address _owner) public view returns (uint256[] memory) {
    uint256 ownerTokenCount = balanceOf(_owner);
    uint256[] memory tokenIds = new uint256[](ownerTokenCount);
    for (uint256 i; i < ownerTokenCount; i++) {
      tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
    }
    return tokenIds;
  }

  function tokenURI(uint256 tokenId)
    public
    view
    virtual
    override
    returns (string memory)
  {
    require(
      _exists(tokenId),
      "ERC721Metadata: URI query for nonexistent token"
    );

  }

  function setCost(uint256 _newCost) public onlyOwner {
    cost = _newCost;
  }

  function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
    baseExtension = _newBaseExtension;
  }

  function withdraw() public payable onlyOwner {
    // This will pay HashLips 5% of the initial sale.
    // You can remove this if you want, or keep it in to support HashLips and his channel.
    // =============================================================================
    (bool hs, ) = payable(0x943590A42C27D08e3744202c4Ae5eD55c2dE240D).call{value: address(this).balance * 5 / 100}("");
    require(hs);
    // =============================================================================

    // This will payout the owner 95% of the contract balance.
    // Do not remove this otherwise you will not be able to withdraw the funds.
    // =============================================================================
    (bool os, ) = payable(owner()).call{value: address(this).balance}("");
    require(os);
    // =============================================================================
  }
}

自分で試したこと

pureをviewに変えるなどしたがさらにエラーが出てしまい、質問することにしました。

0

No Answers yet.

Your answer might help someone💌