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

wip: Example of just getting the nfts #4

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
68fb458
wip: Example of just getting the nfts
Blu-J Jan 16, 2025
7ebf17c
feat: adds hogwards tournament contract
Dan-Nolan Jan 16, 2025
ff43cca
minting page
aashkrishnan Jan 17, 2025
cbeeac9
added a lil contract interaction logic bones
aashkrishnan Jan 17, 2025
13a5510
added more contract interaction logic to mint page
aashkrishnan Jan 17, 2025
c5abcdd
chore: add some horrible looking things
Blu-J Jan 17, 2025
04d1067
Merge remote-tracking branch 'origin/mint_page' into jade/nft-example
Blu-J Jan 17, 2025
4727ef3
wip: shitty points
Blu-J Jan 17, 2025
1e62405
wip: more minor
Blu-J Jan 17, 2025
63a9c98
adds wizard status!
Dan-Nolan Jan 17, 2025
19db0fd
adds the deployed contract
Dan-Nolan Jan 17, 2025
b86053b
chore: Extracting to modules
Blu-J Jan 17, 2025
9e7eb9d
feature: actually fetch the things needed
Blu-J Jan 17, 2025
9f825c6
feat: use the graphql for the other thingy
Blu-J Jan 17, 2025
f9eb418
feat: add in the last of me
Blu-J Jan 17, 2025
e216bdc
feat: last of the updates
Blu-J Jan 17, 2025
70263f7
feat: adds minting logic
linnall Jan 17, 2025
877001f
feat: adds account kit modifications to useScaffoldWriteContract
linnall Jan 17, 2025
da104c2
Merge branch 'jade/nft-example' into mint_page
aashkrishnan Jan 17, 2025
7030a52
Merge pull request #6 from alchemyplatform/mint_page
aashkrishnan Jan 17, 2025
08dc1c6
feat: adds wizard drawings all as jpg
linnall Jan 17, 2025
679c3c9
Merge pull request #7 from alchemyplatform/mint_page
linnall Jan 17, 2025
790c1d7
css updates
CodesMcCabe Jan 17, 2025
352969a
Merge branch 'jade/nft-example' of github.com:alchemyplatform/scaffol…
CodesMcCabe Jan 17, 2025
323d4f7
some ai css changes!
CodesMcCabe Jan 17, 2025
4074719
Merge pull request #8 from alchemyplatform/cm/css-updates
CodesMcCabe Jan 18, 2025
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
3 changes: 3 additions & 0 deletions packages/hardhat/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NEXT_PUBLIC_ALCHEMY_API_KEY=1UHucVGnd1vXCn3FQfCK6J9V1MxckHB8
NEXT_PUBLIC_ALCHEMY_GAS_POLICY_ID=1f0881be-0b44-464e-9d0f-8d641842830a
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=
159 changes: 159 additions & 0 deletions packages/hardhat/contracts/HogwartsTournament.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "hardhat/console.sol";
contract HogwartsTournament is ERC721, ERC721URIStorage, Ownable {
uint256 private _nextTokenId;

enum HogwartsHouse { Gryffindor, Hufflepuff, Ravenclaw, Slytherin }

mapping(address => bool) private _hasMinted;
mapping(uint256 => HogwartsHouse) public tokenHouse;
mapping(HogwartsHouse => uint256) public housePoints;
mapping(uint256 => bool) public isStunned;
mapping(uint256 => string) public wizardNames;

event HousePointsUpdated(HogwartsHouse house, uint256 newPoints);
event NFTMinted(address indexed minter, uint256 tokenId, string tokenURI, HogwartsHouse house, string name);
event WizardStunned(uint256 tokenId);
event WizardRevived(uint256 tokenId, uint256 reviverTokenId);

string private constant GRYFFINDOR_URI = "ipfs://QmGryffindorHash";
string private constant HUFFLEPUFF_URI = "ipfs://QmHufflepuffHash";
string private constant RAVENCLAW_URI = "ipfs://QmRavenclawHash";
string private constant SLYTHERIN_URI = "ipfs://QmSlytherinHash";

constructor(address initialOwner) ERC721("Wizard", "WZRD") Ownable(initialOwner) {}

function safeMint(HogwartsHouse house, string memory wizardName) public {
require(!_hasMinted[msg.sender], "Address has already minted an NFT");
require(uint8(house) <= 3, "Invalid house selection");
require(bytes(wizardName).length > 0, "Wizard name cannot be empty");
require(bytes(wizardName).length <= 40, "Wizard name too long");

uint256 tokenId = _nextTokenId++;
_safeMint(msg.sender, tokenId);

string memory uri;
if (house == HogwartsHouse.Gryffindor) {
uri = GRYFFINDOR_URI;
} else if (house == HogwartsHouse.Hufflepuff) {
uri = HUFFLEPUFF_URI;
} else if (house == HogwartsHouse.Ravenclaw) {
uri = RAVENCLAW_URI;
} else {
uri = SLYTHERIN_URI;
}

_setTokenURI(tokenId, uri);
tokenHouse[tokenId] = house;
wizardNames[tokenId] = wizardName;
_hasMinted[msg.sender] = true;

housePoints[house] += 3;
emit HousePointsUpdated(house, housePoints[house]);
emit NFTMinted(msg.sender, tokenId, uri, house, wizardName);
}

function getTokenHouse(uint256 tokenId) public view returns (HogwartsHouse) {
require(_ownerOf(tokenId) != address(0), "Token does not exist");
return tokenHouse[tokenId];
}

function getHousePoints(HogwartsHouse house) public view returns (uint256) {
return housePoints[house];
}

function modifyHousePoints(HogwartsHouse house, uint256 points, bool add) public onlyOwner {
if (add) {
housePoints[house] += points;
} else {
require(housePoints[house] >= points, "Cannot deduct more points than available");
housePoints[house] -= points;
}
emit HousePointsUpdated(house, housePoints[house]);
}

function tokenURI(uint256 tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) {
return super.tokenURI(tokenId);
}

function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721URIStorage) returns (bool) {
return super.supportsInterface(interfaceId);
}

function rennervate(uint256 targetTokenId) public {
require(_ownerOf(targetTokenId) != address(0), "Target wizard does not exist");
require(isStunned[targetTokenId], "Target wizard is not stunned");

uint256 reviverTokenId;
bool found = false;
uint256 totalTokens = _nextTokenId;

for(uint256 i = 0; i < totalTokens; i++) {
if(ownerOf(i) == msg.sender) {
reviverTokenId = i;
found = true;
break;
}
}

require(found, "Must own a wizard NFT to cast Rennervate");

HogwartsHouse reviverHouse = tokenHouse[reviverTokenId];
HogwartsHouse targetHouse = tokenHouse[targetTokenId];
require(reviverHouse == targetHouse, "Can only revive wizards from your house");

isStunned[targetTokenId] = false;
housePoints[reviverHouse] += 5;
emit HousePointsUpdated(reviverHouse, housePoints[reviverHouse]);
emit WizardRevived(targetTokenId, reviverTokenId);
}

function stupefy(uint256 targetTokenId) public {
require(balanceOf(msg.sender) > 0, "Must own a wizard NFT to cast Stupefy");

uint256 casterTokenId;
uint256 totalTokens = _nextTokenId;

for(uint256 i = 0; i < totalTokens; i++) {
if(ownerOf(i) == msg.sender) {
casterTokenId = i;
break;
}
}

require(_ownerOf(targetTokenId) != address(0), "Target wizard does not exist");
require(!isStunned[targetTokenId], "Wizard is already stunned");
require(tokenHouse[casterTokenId] != tokenHouse[targetTokenId], "Cannot stun wizards from your own house");

isStunned[targetTokenId] = true;
HogwartsHouse casterHouse = tokenHouse[casterTokenId];
housePoints[casterHouse] += 5;
emit HousePointsUpdated(casterHouse, housePoints[casterHouse]);
emit WizardStunned(targetTokenId);
}

function getWizardName(uint256 tokenId) public view returns (string memory) {
require(_ownerOf(tokenId) != address(0), "Token does not exist");
return wizardNames[tokenId];
}

struct WizardStatus {
HogwartsHouse house;
bool stunned;
string name;
}

function getWizardStatus(uint256 tokenId) public view returns (WizardStatus memory) {
require(_ownerOf(tokenId) != address(0), "Token does not exist");
return WizardStatus(
tokenHouse[tokenId],
isStunned[tokenId],
wizardNames[tokenId]
);
}
}
78 changes: 0 additions & 78 deletions packages/hardhat/contracts/YourContract.sol

This file was deleted.

14 changes: 7 additions & 7 deletions packages/hardhat/deploy/00_deploy_your_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { DeployFunction } from "hardhat-deploy/types";
import { Contract } from "ethers";

/**
* Deploys a contract named "YourContract" using the deployer account and
* Deploys a contract named "HogwartsTournament" using the deployer account and
* constructor arguments set to the deployer address
*
* @param hre HardhatRuntimeEnvironment object.
*/
const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const deployHogwartsTournament: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
/*
On localhost, the deployer account is the one that comes with Hardhat, which is already funded.

Expand All @@ -22,7 +22,7 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;

await deploy("YourContract", {
await deploy("HogwartsTournament", {
from: deployer,
// Contract constructor arguments
args: [deployer],
Expand All @@ -33,12 +33,12 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn
});

// Get the deployed contract to interact with it after deploying.
const yourContract = await hre.ethers.getContract<Contract>("YourContract", deployer);
console.log("👋 Initial greeting:", await yourContract.greeting());
const hogwartsTournament = await hre.ethers.getContract<Contract>("HogwartsTournament", deployer);
console.log("🧙 Hogwarts Tournament deployed to:", hogwartsTournament.target);
};

export default deployYourContract;
export default deployHogwartsTournament;

// Tags are useful if you have multiple deploy files and only want to run one of them.
// e.g. yarn deploy --tags YourContract
deployYourContract.tags = ["YourContract"];
deployHogwartsTournament.tags = ["HogwartsTournament"];
Loading