[TIL] 23/04/19,20

HyeongA·2023년 4월 20일

TIL

목록 보기
19/25
post-thumbnail

DAY 24, 25 : solidity 맛보기

1. 토큰 발행

  • 관련 이용 웹사이트
  1. ERC관련 : https://www.openzeppelin.com/contracts
  2. MATIC충전 : https://faucet.polygon.technology/
  3. 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);
    }
}

2. NFT 발행

  1. 이더리움과 상호작용할 수 있는 라이브러리
  2. 설치 명령어 : npm i web3
  3. 스마트 컨트랙트와 통신
    - 읽을때 : call 함수
    - 기록할때 : send 함수 (gas 비용 발생)

  • 관련 이용 웹사이트
  1. 오픈시 테스트넷 : https://testnets.opensea.io/
  2. IPFS(클라우드 형태로 이용) : https://www.pinata.cloud/
  3. 픽셀아트 : 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];
    }
}
profile
Today I Learned

0개의 댓글