0
0

【Alchemy】NFTのスマートコントラクト(ERC721)の作成方法

Last updated at Posted at 2023-10-29

Alchemyのチュートリアルを見ながらやりました。

Openzeppelin Wizard

Openzeppelin Wizardにアクセス
https://wizard.openzeppelin.com/

ERC721 のタブをクリックし、
トークンの名前を入力 する・

私の名前 Tatsuya トークン 「TTY」 にした。

Image from Gyazo


FEATURES の設定はよく分からないので、 Alchemyのサイトの例のとおりにした。


「Open Remix」をクリックすると、
Image from Gyazo

Remixが立ち上がる。

Remix

Openzeppelin Wizardで作成されたコードが自動的に移記されている。

contract-98fa00c16a.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

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

contract Tatsuya is ERC721, ERC721Enumerable, ERC721URIStorage, Ownable {
    uint256 private _nextTokenId;

    constructor(address initialOwner)
        ERC721("Tatsuya", "TTY")
        Ownable(initialOwner)
    {}

    function safeMint(address to, string memory uri) public onlyOwner {
        uint256 tokenId = _nextTokenId++;
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri);
    }

    // The following functions are overrides required by Solidity.

    function _update(address to, uint256 tokenId, address auth)
        internal
        override(ERC721, ERC721Enumerable)
        returns (address)
    {
        return super._update(to, tokenId, auth);
    }

    function _increaseBalance(address account, uint128 value)
        internal
        override(ERC721, ERC721Enumerable)
    {
        super._increaseBalance(account, value);
    }

    function tokenURI(uint256 tokenId)
        public
        view
        override(ERC721, ERC721URIStorage)
        returns (string memory)
    {
        return super.tokenURI(tokenId);
    }

    function supportsInterface(bytes4 interfaceId)
        public
        view
        override(ERC721, ERC721Enumerable, ERC721URIStorage)
        returns (bool)
    {
        return super.supportsInterface(interfaceId);
    }
}

バージョンを同じにあわせ、コンパイルする。
Image from Gyazo


DEPLOY & RUN TRANSACTION に移動
  1. ENVIRONMENT : Injected Web3
    MetaMask が立ち上がる。
  2. CONTRACT :  さっき作ったコントラクト
  3. 最初にいれるウォレットのアドレス
    4. Deploy をクリック

コントラクトが作成される

コントラクトアドレスはこちら

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0