DAY 24, 25 : solidity 맛보기
- 관련 이용 웹사이트
- ERC관련 : https://www.openzeppelin.com/contracts
- MATIC충전 : https://faucet.polygon.technology/
- Remix (코드작성) : https://remix.ethereum.org/#lang=en&optimize=false&runs=200&evmVersion=null&version=soljson-v0.8.18+commit.87f61d96.js
MintToken.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; contract MintToken is ERC20Burnable { constructor(uint256 _initialSupply, string memory _name, string memory _symbol) ERC20(_name, _symbol) { // _mint(msg.sender, _initialSupply); _mint(msg.sender, _initialSupply * 10 ** 18); } }
- Web3.js (https://web3js.readthedocs.io/en/v1.8.2/)
- 이더리움과 상호작용할 수 있는 라이브러리
- 설치 명령어 :
npm i web3- 스마트 컨트랙트와 통신
- 읽을때 : call 함수
- 기록할때 : send 함수 (gas 비용 발생)
- 관련 이용 웹사이트
- 오픈시 테스트넷 : https://testnets.opensea.io/
- IPFS(클라우드 형태로 이용) : https://www.pinata.cloud/
- 픽셀아트 : https://www.pixilart.com/draw
MintNft.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; contract MintNft is ERC721Enumerable { mapping(uint => string) public metadataUri; uint public totalNft; constructor(string memory _name, string memory _symbol) ERC721(_name, _symbol) {} function mintNft(string memory _metadataUri) public { uint tokenId = totalSupply() + 1; _mint(msg.sender, tokenId); metadataUri[tokenId] = _metadataUri; } function tokenURI(uint _tokenId) public override view returns(string memory) { return metadataUri[_tokenId]; } }