Skip to content
Open
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
201 changes: 0 additions & 201 deletions LICENSE

This file was deleted.

51 changes: 0 additions & 51 deletions README.md

This file was deleted.

37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "Celo-Auction-DApp",
"version": "1.0.0",
"description": "Custom Celo Composer project.",
"private": true,
"author": "Celo",
"license": "MIT",
"scripts": {
"react-app:dev": "yarn workspace @Celo-Auction-DApp/react-app dev",
"react-app:build": "yarn workspace @Celo-Auction-DApp/react-app build",
"react-app:start": "yarn workspace @Celo-Auction-DApp/react-app start",
"react-app:lint": "yarn workspace @Celo-Auction-DApp/react-app lint",
"hardhat:test": "yarn workspace @Celo-Auction-DApp/hardhat test",
"hardhat:test-local": "yarn workspace @Celo-Auction-DApp/hardhat test-local",
"hardhat:accounts": "yarn workspace @Celo-Auction-DApp/hardhat accounts",
"hardhat:devchain": "yarn workspace @Celo-Auction-DApp/hardhat devchain",
"hardhat:deploy": "yarn workspace @Celo-Auction-DApp/hardhat deploy",
"hardhat:deploy-reset-watch": "yarn workspace @Celo-Auction-DApp/hardhat deploy-reset-watch",
"hardhat:watch": "yarn workspace @Celo-Auction-DApp/hardhat watch",
"hardhat:fork-mainnet": "yarn workspace @Celo-Auction-DApp/hardhat fork-mainnet"
},
"repository": {
"type": "git",
"url": "git+https://github.com/celo-org/celo-composer.git"
},
"bugs": {
"url": "https://github.com/celo-org/celo-composer/issues"
},
"homepage": "https://github.com/celo-org/celo-composer/blob/main/README.md",
"workspaces": [
"packages/*"
],
"keywords": [
"celo-composer",
"celo"
]
}
76 changes: 76 additions & 0 deletions packages/hardhat/contracts/GamifiedOnChainNFT.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/Base64.sol";

contract GamifiedOnChainNFT is ERC721URIStorage {
using Strings for uint256;
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;

mapping(uint256 => uint256) public tokenIdToLevels;

constructor() ERC721 ("Gamify OnChainNFT", "GOCNFT"){
}

function generateCharacter(uint256 tokenId) public view returns(string memory){

bytes memory svg = abi.encodePacked(
'<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMin meet" viewBox="0 0 350 350">',
'<style>.base { fill: black; font-family: serif; font-size: 14px; }</style>',
'<rect width="100%" height="100%" fill="yellow" />',
'<text x="50%" y="40%" class="base" dominant-baseline="middle" text-anchor="middle">',"Celo games",'</text>',
'<text x="50%" y="50%" class="base" dominant-baseline="middle" text-anchor="middle">', "Levels: ",getLevels(tokenId),'</text>',
'</svg>'
);

return string(
abi.encodePacked(
"data:image/svg+xml;base64,",
Base64.encode(svg)
)
);
}

function getLevels(uint256 tokenId) public view returns (string memory) {
uint256 levels = tokenIdToLevels[tokenId];
return levels.toString();
}

function getTokenURI(uint256 tokenId) public returns (string memory){
bytes memory dataURI = abi.encodePacked(
'{',
'"name": "Gamify OnChainNFT #', tokenId.toString(), '",',
'"description": "Game Battle on Celo blockchain",',
'"image": "', generateCharacter(tokenId), '"',
'}'
);
return string(
abi.encodePacked(
"data:application/json;base64,",
Base64.encode(dataURI)
)
);
}

function mint() public {
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_safeMint(msg.sender, newItemId);
tokenIdToLevels[newItemId] = 0;
_setTokenURI(newItemId, getTokenURI(newItemId));
}

function play(uint256 tokenId) public {
require(_exists(tokenId), "Please use an existing token");
require(ownerOf(tokenId) == msg.sender, "You must own this token to play with it");
uint256 currentLevel = tokenIdToLevels[tokenId];
tokenIdToLevels[tokenId] = currentLevel + 1;
_setTokenURI(tokenId, getTokenURI(tokenId));
}


}
Loading