-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
to10
committed
Jun 21, 2022
0 parents
commit 0b74020
Showing
17 changed files
with
1,052 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
contracts/artifacts/ | ||
.deps/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 toto-1010 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# 概要 | ||
私、ととが製作した学習教材の一部です。 | ||
|
||
これからNFTスマートコントラクト開発を学習される方々向けの学習コースで使用したソースコードを無償提供します。 | ||
※DApp(分散アプリケーション)やスマートコントラクト開発における知識、技術力向上が主な目的です。私は日本におけるこれらの技術発展を望む者です。 | ||
|
||
コードの解説については現在動画(現時点では有料)のみで行なっています。もし関心のある方いらっしゃればご覧ください。 | ||
|
||
|
||
|
||
### 注意事項 | ||
このGitHubリポジトリにあるソースコードは学習目的のものです。 | ||
このリポジトリで提供するソースコード以外、例えばコースの解説動画や資料、NFT画像、その他の著作権をはじめとする全ての権利は私、ととが有しています。 | ||
- ソースコードそのものはコースの受講者か否かに限らず[MITライセンス](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/LICENSE "MIT LICENSE")のもと、無償提供しますが、そのまま使ったり、切り貼りしたりしてご自身のNFTコントラクトを開発し、Ethereumなどのメインネットワークにデプロイすることは推奨しません。 | ||
- MITライセンス記載の通り、これを禁止するものではありませんが、「本ソフトウェアの使用またはその他の取引に起因または関連して発生した、いかなるクレーム、損害またはその他の責任についても、著作者または著作権所有者は一切責任を負いません。」 と記載がある通り、利用の際はご自身の責任のもと行なってください。 | ||
- 本GitHubリポジトリから直接Q&Aは受け付けていませんのでご了承ください。 | ||
|
||
|
||
|
||
### 解説動画とソースコードのリンク | ||
|
||
#### Section01 はじめに | ||
- ソースコード | ||
- なし | ||
|
||
#### Section02 ERC-721とスマートコントラクトの基礎知識 | ||
- ソースコード | ||
- なし | ||
|
||
#### Section03 EOAアドレス生成とトランザクション基礎知識およびウォレット環境準備 | ||
- ソースコード | ||
- なし | ||
|
||
#### Section04 【コアNFT】はじめてのNFTスマートコントラクト開発 | ||
- ソースコード | ||
- [MyNFT.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section04/MyNFT.sol "MyNFT.sol") | ||
|
||
#### Section05 スマートコントラクトのファンクション実行制御 | ||
- ソースコード1 | ||
- [OnlyOwnerMint.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section05/OnlyOwnerMint.sol "OnlyOwnerMint.sol") | ||
- ソースコード2 | ||
- [OnlyOwnerMintWithModifier.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section05/OnlyOwnerMintWithModifier.sol "OnlyOwnerMintWithModifier.sol") | ||
- ソースコード3 | ||
- [OZOnlyOwnerMint.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section05/OZOnlyOwnerMint.sol "OZOnlyOwnerMint.sol") | ||
|
||
#### Section06 【分散型ストレージソリューション】IPFS/Filecoin | ||
- ソースコード | ||
- なし | ||
|
||
#### Section07 【オフチェーンNFT】スマートコントラクト開発 | ||
- ソースコード1 | ||
- [OffURIChangeable.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section07/OffURIChangeable.sol "OffURIChangeable.sol") | ||
- 【参考】トランザクション1 | ||
- [Etherscan transaction](https://rinkeby.etherscan.io/address/0x8e7e1e7a43e2a3f26b046842415aff8f4b30728a "OffURIChangeable transaction") | ||
- 【参考】NFT(OpenSea)1 | ||
- [テスト用OpenSea](https://testnets.opensea.io/collection/offurichangeable-v2 "OffURIChangeable NFT") | ||
- ソースコード2 | ||
- [OffURIUnchangeable.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section07/OffURIUnchangeable.sol "OffURIUnchangeable.sol") | ||
- 【参考】トランザクション2 | ||
- [Etherscan transaction](https://rinkeby.etherscan.io/address/0xac8734b211e6661f062a7d95b1bf84c9f1144e8c "OffURIUnchangeable transaction") | ||
- 【参考】NFT(OpenSea)2 | ||
- [テスト用OpenSea](https://testnets.opensea.io/collection/offuriunchangeable-v2 "OffURIUnchangeable NFT") | ||
|
||
#### Section08 Event発行とIncremental tokenId | ||
- ソースコード1 | ||
- [EventNFT.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section08/EventNFT.sol "EventNFT.sol") | ||
- 【参考】トランザクション1 | ||
- [Etherscan transaction](https://rinkeby.etherscan.io/address/0x31dbf12b020ad39f950b8e5c8447dc81cce5d451#events "EventNFT transaction") | ||
- ソースコード2 | ||
- [CounterNFT.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section08/CounterNFT.sol "CounterNFT.sol") | ||
- 【参考】トランザクション2 | ||
- [Etherscan transaction](https://rinkeby.etherscan.io/address/0xa732c62d0c7361472fa14905b41b55eb09b9e605 "CounterNFT transaction") | ||
- 【参考】NFT(OpenSea)2 | ||
- [テスト用OpenSea](https://testnets.opensea.io/collection/counternft-v3 "CounterNFT NFT") | ||
|
||
|
||
#### Section09 NFTの削除と停止ができるスマートコントラクト開発 | ||
- ソースコード1 | ||
- [BurnableNFT.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section09/BurnableNFT.sol "BurnableNFT.sol") | ||
- ソースコード2 | ||
- [PausableNFT.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section09/PausableNFT.sol "PausableNFT.sol") | ||
|
||
#### Section10 スマートコントラクトコードの検証とオープンソース化 | ||
- ソースコード | ||
- なし | ||
|
||
#### Section11 【オンチェーンNFT】スマートコントラクト開発 | ||
- ソースコード | ||
- [OnURIUnchangeable.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section11/OnURIUnchangeable.sol "OnURIUnchangeable.sol") | ||
- 【参考】トランザクション | ||
- [Etherscan transaction](https://rinkeby.etherscan.io/address/0x654f0a4bbadfb78537de15e534562cb37509c44c "OnURIUnchangeable transaction") | ||
- 【参考】NFT(OpenSea) | ||
- [テスト用OpenSea](https://testnets.opensea.io/collection/onuriunchangeable-v4 "OnURIUnchangeable NFT") | ||
|
||
#### Section12 【オンチェーン擬似ランダムNFT】スマートコントラクト開発 using keccak256 hash | ||
- ソースコード | ||
- [OnRandomURIKeccak.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section12/OnRandomURIKeccak.sol "OnRandomURIKeccak.sol") | ||
- 【参考】トランザクション | ||
- [Etherscan transaction](https://mumbai.polygonscan.com/address/0x0f8115b50678c89f81453d48815d02b65847b5f3 "OnRandomURIKeccak transaction") | ||
- 【参考】NFT(OpenSea) | ||
- [テスト用OpenSea](https://testnets.opensea.io/collection/onrandomurikeccak-hhmawi2ptr "OnRandomURIKeccak NFT") | ||
|
||
#### Section13 【オラクルソリューション】Chainlink VRF | ||
- ソースコード | ||
- [ChainlinkVRFDemo.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section13/ChainlinkVRFDemo.sol "ChainlinkVRFDemo.sol") | ||
|
||
#### Section14 【オンチェーンランダムNFT】スマートコントラクト開発 using Chainlink VRF | ||
- ソースコード | ||
- [OnRandomURIOracle.sol](https://github.com/toto-1010/nft-smart-contracts-basic1/blob/main/contracts/lecture-code/Section14/OnRandomURIOracle.sol "OnRandomURIOracle.sol"). | ||
- 【参考】トランザクション | ||
- [Etherscan transaction](https://rinkeby.etherscan.io/address/0x65334d7e31064df0d257171a46d38dce0b45d638 "OnRandomURIOracle transaction") | ||
- 【参考】NFT(OpenSea) | ||
- [テスト用OpenSea](https://testnets.opensea.io/collection/onrandomurioracle-v4 "OnRandomURIOracle NFT") | ||
|
||
|
||
#### Section15 NFTの権限移譲(Approve)と移転(Transfer) | ||
- ソースコード | ||
- なし | ||
|
||
#### Section16 さいごに | ||
- ソースコード | ||
- なし |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.14; | ||
|
||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
|
||
contract MyNFT is ERC721 { | ||
|
||
constructor() ERC721("MyNFT", "MYNFT") {} | ||
|
||
function nftMint(address to, uint256 tokenId) public { | ||
_mint(to, tokenId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.14; | ||
|
||
import "@openzeppelin/contracts@4.6.0/token/ERC721/ERC721.sol"; | ||
import "@openzeppelin/contracts@4.6.0/access/Ownable.sol"; | ||
|
||
contract OZOnlyOwnerMint is ERC721, Ownable { | ||
|
||
constructor() ERC721("OZOnlyOwnerMint", "OZOWNER") {} | ||
|
||
/** | ||
* @dev | ||
* - このコントラクトをデプロイしたアドレスだけがmint可能 onlyOwner | ||
* - nftMint関数実行アドレス(=デプロイアドレス)にtokenIdを紐づけ _msgSender() | ||
*/ | ||
function nftMint(uint256 tokenId) public onlyOwner { | ||
_mint(_msgSender(), tokenId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.14; | ||
|
||
import "@openzeppelin/contracts@4.6.0/token/ERC721/ERC721.sol"; | ||
|
||
contract OnlyOwnerMint is ERC721 { | ||
|
||
/** | ||
* @dev | ||
* - このコントラクトをデプロイしたアドレス用変数 owner | ||
*/ | ||
address public owner; | ||
|
||
constructor() ERC721("OnlyOwnerMint", "OWNER") { | ||
owner = _msgSender(); | ||
} | ||
|
||
/** | ||
* @dev | ||
* - このコントラクトをデプロイしたアドレスだけがmint可能 require | ||
* - nftMint関数実行アドレス(=デプロイアドレス)にtokenIdを紐づけ _msgSender() | ||
*/ | ||
function nftMint(uint256 tokenId) public { | ||
require(owner == _msgSender(), "Caller is not the owner"); | ||
_mint(_msgSender(), tokenId); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
contracts/lecture-codes/Section05/OnlyOwnerMintWithModifier.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.14; | ||
|
||
import "@openzeppelin/contracts@4.6.0/token/ERC721/ERC721.sol"; | ||
|
||
contract OnlyOwnerMintWithModifier is ERC721 { | ||
|
||
/** | ||
* @dev | ||
* - このコントラクトをデプロイしたアドレス用変数 owner | ||
*/ | ||
address public owner; | ||
|
||
constructor() ERC721("OnlyOwnerMintWithModifier", "OWNERMOD") { | ||
owner = _msgSender(); | ||
} | ||
|
||
/** | ||
* @dev | ||
* - このコントラクトをデプロイしたアドレスだけに制限するmodifier修飾子 onlyOwner() | ||
*/ | ||
modifier onlyOwner() { | ||
require(owner == _msgSender(), "Caller is not the owner"); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev | ||
* - このコントラクトをデプロイしたアドレスだけがmint可能 onlyOwner | ||
* - nftMint関数実行アドレス(=デプロイアドレス)にtokenIdを紐づけ _msgSender() | ||
*/ | ||
function nftMint(uint256 tokenId) public onlyOwner { | ||
_mint(_msgSender(), tokenId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.14; | ||
|
||
import "@openzeppelin/contracts@4.6.0/token/ERC721/ERC721.sol"; | ||
import "@openzeppelin/contracts@4.6.0/access/Ownable.sol"; | ||
import "@openzeppelin/contracts@4.6.0/token/ERC721/extensions/ERC721URIStorage.sol"; | ||
|
||
contract OffURIChangeable is ERC721URIStorage, Ownable { | ||
|
||
constructor() ERC721("OffURIChangeable", "OFFC") {} | ||
|
||
/** | ||
* @dev | ||
* - このコントラクトをデプロイしたアドレスだけがmint可能 onlyOwner | ||
* - nftMint関数実行アドレス(=デプロイアドレス)にtokenIdを紐づけ _msgSender() | ||
*/ | ||
function nftMint(uint256 tokenId) public onlyOwner { | ||
_mint(_msgSender(), tokenId); | ||
} | ||
|
||
/** | ||
* @dev | ||
* - 既存のtokenIdにURIを紐付け | ||
*/ | ||
function setTokenURI(uint256 tokenId, string calldata uri) public onlyOwner { | ||
_setTokenURI(tokenId, uri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.14; | ||
|
||
import "@openzeppelin/contracts@4.6.0/token/ERC721/ERC721.sol"; | ||
import "@openzeppelin/contracts@4.6.0/access/Ownable.sol"; | ||
import "@openzeppelin/contracts@4.6.0/token/ERC721/extensions/ERC721URIStorage.sol"; | ||
|
||
contract OffURIUnchangeable is ERC721URIStorage, Ownable { | ||
|
||
constructor() ERC721("OffURIUnchangeable", "OFFU") {} | ||
|
||
/** | ||
* @dev | ||
* - このコントラクトをデプロイしたアドレスだけがmint可能 onlyOwner | ||
* - nftMint関数実行アドレス(=デプロイアドレス)にtokenIdを紐づけ _msgSender() | ||
* - mintの際にURIを設定 _setTokenURI() | ||
*/ | ||
function nftMint(uint256 tokenId, string calldata uri) public onlyOwner { | ||
_mint(_msgSender(), tokenId); | ||
_setTokenURI(tokenId, uri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.14; | ||
|
||
import "@openzeppelin/contracts@4.6.0/token/ERC721/ERC721.sol"; | ||
import "@openzeppelin/contracts@4.6.0/access/Ownable.sol"; | ||
import "@openzeppelin/contracts@4.6.0/token/ERC721/extensions/ERC721URIStorage.sol"; | ||
import "@openzeppelin/contracts@4.6.0/utils/Counters.sol"; | ||
import "@openzeppelin/contracts@4.6.0/utils/Strings.sol"; | ||
|
||
contract CounterNFT is ERC721URIStorage, Ownable { | ||
|
||
/** | ||
* @dev | ||
* - _tokenIdsはCountersの全関数が利用可能 | ||
*/ | ||
using Counters for Counters.Counter; | ||
Counters.Counter private _tokenIds; | ||
|
||
/** | ||
* @dev | ||
* - URI設定時に誰がどのtokenIdに何のURIを設定したか記録する | ||
*/ | ||
event TokenURIChanged(address indexed sender, uint256 indexed tokenId, string uri); | ||
|
||
constructor() ERC721("CounterNFT", "COUNT") {} | ||
|
||
/** | ||
* @dev | ||
* - このコントラクトをデプロイしたアドレスだけがmint可能 onlyOwner | ||
* - tokenIdをインクリメント _tokenIds.increment() | ||
* - nftMint関数実行アドレス(=デプロイアドレス)にtokenIdを紐づけ _msgSender() | ||
* - mintの際にURIを設定 _setTokenURI() | ||
* - EVENT発火 emit TokenURIChanged | ||
*/ | ||
function nftMint() public onlyOwner { | ||
_tokenIds.increment(); | ||
uint256 newTokenId = _tokenIds.current(); | ||
|
||
_mint(_msgSender(), newTokenId); | ||
|
||
string memory jsonFile = string(abi.encodePacked('metadata', Strings.toString(newTokenId), '.json')); | ||
_setTokenURI(newTokenId, jsonFile); | ||
|
||
emit TokenURIChanged(_msgSender(), newTokenId, jsonFile); | ||
} | ||
|
||
/** | ||
* @dev | ||
* - URIプレフィックスの設定 | ||
*/ | ||
function _baseURI() internal pure override returns (string memory) { | ||
return "ipfs://bafybeigyod7ldrnytkzrw45gw2tjksdct6qaxnsc7jdihegpnk2kskpt7a/"; | ||
} | ||
} |
Oops, something went wrong.