블록체인 하나씩 알아보기 :: Market
코인을 만들었어요.
2022.07.19 - [IT 인터넷/Blockchain] - 블록체인 하나씩 알아보기 :: ERC20
블록체인 하나씩 알아보기 :: ERC20
mint와 burn을 제공하는 간단한 것부터 해볼게요. BanjubuCoin.sol // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/c..
banjubu.tistory.com
NFT도 만들었고요.
2022.07.19 - [IT 인터넷/Blockchain] - 블록체인 하나씩 알아보기 :: ERC721
블록체인 하나씩 알아보기 :: ERC721
코인은 만들었고요. 2022.07.19 - [IT 인터넷/Blockchain] - 블록체인 하나씩 알아보기 :: ERC20 블록체인 하나씩 알아보기 :: ERC20 mint와 burn을 제공하는 간단한 것부터 해볼게요. BanjubuCoin.sol // SPDX-Li..
banjubu.tistory.com
이제 마켓을 만들고 NFT를 판매할게요.
BanjubuMarket.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract BanjubuMarket is Ownable {
address private _coinContract;
address private _nftContract;
mapping(uint256 => address) private nftOwners;
mapping(uint256 => uint256) private nftPrices;
function initialize(address coinContract, address nftContract) public onlyOwner {
_coinContract = coinContract;
_nftContract = nftContract;
}
function sellNFT(uint256 tokenId, uint256 coinAmount) public {
ERC721(_nftContract).transferFrom(msg.sender, address(this), tokenId);
nftOwners[tokenId] = msg.sender;
nftPrices[tokenId] = coinAmount;
}
function buyNFT(uint256 tokenId) public {
ERC721(_nftContract).transferFrom(address(this), msg.sender, tokenId);
uint256 coinAmount = nftPrices[tokenId];
ERC20(_coinContract).transferFrom(msg.sender, address(this), coinAmount);
ERC20(_coinContract).transfer(nftOwners[tokenId], coinAmount);
delete nftOwners[tokenId];
delete nftPrices[tokenId];
}
}
Rinkeby에 올렸어요.
https://rinkeby.etherscan.io/address/0xFD36a32354aE223B5b176F0D7c89E04f13e31bd8
BanjubuMarket | Address 0xFD36a32354aE223B5b176F0D7c89E04f13e31bd8 | Etherscan
The Contract Address 0xFD36a32354aE223B5b176F0D7c89E04f13e31bd8 page allows users to view the source code, transactions, balances, and analytics for the contract address. Users can also interact and make transactions to the contract directly on Etherscan.
rinkeby.etherscan.io
초기화 먼저 할게요.
판매하고 다른 사용자로 구매하면 끝.
영어, 중국어 공부중이신가요?
홈스쿨 교재. 한 권으로 가족 모두 할 수 있어요!
한GLO 미네르바에듀 : 네이버쇼핑 스마트스토어
한글로 영어가 된다?! 한글로[한GLO]는 영어 중국어 일어 러시아어 스페인어가 됩니다!!
smartstore.naver.com