Skip to content

Commit

Permalink
Working on adding TokenURI
Browse files Browse the repository at this point in the history
  • Loading branch information
adriandelgg committed Jun 14, 2021
1 parent 4042ecf commit 56f4f42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions contracts/ColorMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "../node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721En
*/

// Charge a few in order to mint a token
// Set Token URI w/ IPFS metadata
contract ColorMinter is ERC721Enumerable {
// The token ID that will be given to new minted tokens.
uint256 private _tokenId;
Expand All @@ -25,13 +26,14 @@ contract ColorMinter is ERC721Enumerable {

// Ex: "#21F32"
// Mints a new token based on a HEX color.
function mint(string memory _color) public {
// Must accept only HEX colors
function mint(string memory _color) internal returns (uint256) {
require(msg.value == 1e12, "Amount sent must be 1e12.");
require(!_colorExists[_color], "NFT already exists!");
_safeMint(msg.sender, _tokenId);
_colorExists[_color] = true;
_tokenValue[_tokenId] = _color;
_tokenId++;
return _tokenId - 1;
}

// The total amount of tokens that have been minted.
Expand Down
10 changes: 6 additions & 4 deletions contracts/Exchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity ^0.8.0;

import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";
import "../node_modules/@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import "../node_modules/@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./ColorMinter.sol";

/**
Expand All @@ -15,8 +14,6 @@ import "./ColorMinter.sol";
*/

contract Exchange is Ownable, ColorMinter, ERC721Holder {
using SafeMath for uint256;

receive() external payable {}

fallback() external payable {}
Expand Down Expand Up @@ -54,6 +51,11 @@ contract Exchange is Ownable, ColorMinter, ERC721Holder {
return _tokenInfo[_tokenId];
}

function mintNFT(string memory _tokenUri) public payable {
uint256 tokenId = mint(_tokenUri);
// _setTokenURI(tokenId, _tokenUri); //Needs to set tokenURI
}

/**
* @dev Allows a user to sell their NFT to the DEX and also specify
* their sell price in wei. Checks to make sure the sell price is greater or equal
Expand Down Expand Up @@ -128,7 +130,7 @@ contract Exchange is Ownable, ColorMinter, ERC721Holder {
address _tokenOwner,
uint256 _tokenSalePrice
) private {
uint256 payAmount = _tokenSalePrice.sub(1e12);
uint256 payAmount = _tokenSalePrice - 1e12;
(bool success, ) = _tokenOwner.call{value: payAmount}("");
require(success, "Transaction failed.");
}
Expand Down

0 comments on commit 56f4f42

Please sign in to comment.