Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart contract integration with API - part 1 #4

Merged
merged 4 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ ___

___

Note: `game` branch
* Polygon-based smart contract for NFT cards
* Building an [api component](https://github.com/signal-k/dabpi) on top of smart contract
* Build moralis api into this branch


## 📝 What is "Signal-K/polygon"?

Expand Down
Binary file removed contracts/.DS_Store
Binary file not shown.
28 changes: 0 additions & 28 deletions contracts/1_Storage.sol

This file was deleted.

51 changes: 0 additions & 51 deletions contracts/2_Owner.sol

This file was deleted.

138 changes: 0 additions & 138 deletions contracts/3_Ballot.sol

This file was deleted.

85 changes: 85 additions & 0 deletions contracts/CreditTokenRef.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract LipToken is ERC721, Ownable {
constructor(string memory _name, string memory _symbol)
ERC721(_name, _symbol)
{}

uint256 COUNTER;

uint256 fee = 0.01 ether;

struct Lip {
string name;
uint256 id;
uint256 dna;
uint8 level;
uint8 rarity;
}

Lip[] public lips;

event NewLip(address indexed owner, uint256 id, uint256 dna);

// Helpers
function _createRandomNum(uint256 _mod) internal view returns (uint256) {
uint256 randomNum = uint256(
keccak256(abi.encodePacked(block.timestamp, msg.sender))
);
return randomNum % _mod;
}

function updateFee(uint256 _fee) external onlyOwner {
fee = _fee;
}

function withdraw() external payable onlyOwner {
address payable _owner = payable(owner());
_owner.transfer(address(this).balance);
}

// Creation
function _createLip(string memory _name) internal {
uint8 randRarity = uint8(_createRandomNum(100));
uint256 randDna = _createRandomNum(10**16);
Lip memory newLip = Lip(_name, COUNTER, randDna, 1, randRarity);
lips.push(newLip);
_safeMint(msg.sender, COUNTER);
emit NewLip(msg.sender, COUNTER, randDna);
COUNTER++;
}

function createRandomLip(string memory _name) public payable {
require(msg.value >= fee);
_createLip(_name);
}

// Getters
function getLips() public view returns (Lip[] memory) {
return lips;
}

function getOwnerLips(address _owner) public view returns (Lip[] memory) {
Lip[] memory result = new Lip[](balanceOf(_owner));
uint256 counter = 0;
for (uint256 i = 0; i < lips.length; i++) {
if (ownerOf(i) == _owner) {
result[counter] = lips[i];
counter++;
}
}
return result;
}

// Actions
function levelUp(uint256 _lipId) public {
require(ownerOf(_lipId) == msg.sender);
Lip storage lip = lips[_lipId];
lip.level++;
}
}
32 changes: 32 additions & 0 deletions contracts/GearToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";

contract GearToken is ERC721, Ownable {
uint256 COUNTER; // Incremental function for indexing of NFTs

struct Gear {
string name;
uint256 id;
uint256 dna;
uint8 level;
uint8 rarity;
}

Gear[] public gears;

constructor(string memory _name, string memory _symbol)
ERC721(_name, _symbol)
{}

// Minting function
function _createGear(string memory _name, uint256 _dna) internal {
Gear memory newGear = Gear(_name, COUNTER, _dna, 1, 50);
gears.push(newGear); // Adds the new gear onto the array
/*_safeMint(_to, COUNTER); // Who is the NFT for?, what is the identifier of the NFT that's being minted?
COUNTER++;*/
}
}
14 changes: 0 additions & 14 deletions contracts/Token.sol

This file was deleted.

Loading