Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adisingh925 committed Jun 18, 2024
0 parents commit a7b4372
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.sol linguist-language=Solidity
*.vy linguist-language=Python
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__pycache__
.env
.history
.hypothesis/
build/
reports/
28 changes: 28 additions & 0 deletions brownie-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
dependencies:
- smartcontractkit/chainlink-brownie-contracts@1.1.1
- OpenZeppelin/openzeppelin-contracts@5.0.2
compiler:
solc:
remappings:
- '@chainlink=smartcontractkit/chainlink-brownie-contracts@1.1.1'
- '@openzeppelin=OpenZeppelin/openzeppelin-contracts@5.0.2'


networks:
default: "mainnet-fork"
mainnet-fork:
eth_usd_price_feed: '0x773616E4d11A78F511299002da57A0a94577F1f4'
vrf_coordinator: '0x8103B0A8A00be2DDC778e6e7eaa21791Cd364625'
key_hash: '0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c'
subscription_id: "1"
verify: False
sepolia:
vrf_coordinator: '0x9DdfaCa8183c41ad55329BdeeD9F6A8d53168B1B'
key_hash: '0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae'
subscription_id: "53916136300377756998912187517104510161561390681202716693667563979261474113768"
verify: True


dotenv: .env
wallets :
from_key : ${PRIVATE_KEY}
74 changes: 74 additions & 0 deletions contracts/AdvancedCollectible.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import {VRFConsumerBaseV2Plus} from "@chainlink/contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Plus.sol";
import {VRFV2PlusClient} from "@chainlink/contracts/src/v0.8/vrf/dev/libraries/VRFV2PlusClient.sol";

contract AdvancedCollectible is ERC721URIStorage, VRFConsumerBaseV2Plus{

bytes32 immutable public KEY_HASH;
uint256 immutable public SUBSCRIPTION_ID;
uint256 public tokenCounter;
address public ownerAddress;

// Constants
uint32 constant public CALLBACK_GAS_LIMIT = 1000000;
uint16 constant public REQUEST_CONFORMATIONS = 3;
uint32 constant public NUM_WORDS = 1;

mapping(uint256 => address) public requestIdToSender;
mapping(uint256 => BREED) public tokenIdToBreed;

enum BREED{
PUG,
BULLDOG,
BEAGLE,
POODLE
}

string[] public tokenURIs = [
"https://nft-backend-psi.vercel.app/1",
"https://nft-backend-psi.vercel.app/2",
"https://nft-backend-psi.vercel.app/3",
"https://nft-backend-psi.vercel.app/4"
];

event requestedCollectible(uint256 requestId, address creator);
event breedAssignedToToken(uint256 tokenId, BREED breed);

constructor(address _vrfCoordinator, uint256 _subscriptionId, bytes32 _keyHash) VRFConsumerBaseV2Plus(_vrfCoordinator) ERC721("Dogie", "Dog") {
KEY_HASH = _keyHash;
SUBSCRIPTION_ID = _subscriptionId;
tokenCounter = 0;
ownerAddress = msg.sender;
}

function createCollectible() public {
uint256 requestId = s_vrfCoordinator.requestRandomWords(
VRFV2PlusClient.RandomWordsRequest({
keyHash: KEY_HASH,
subId: SUBSCRIPTION_ID,
requestConfirmations: REQUEST_CONFORMATIONS,
callbackGasLimit: CALLBACK_GAS_LIMIT,
numWords: NUM_WORDS,
// Set nativePayment to true to pay for VRF requests with Sepolia ETH instead of LINK
extraArgs: VRFV2PlusClient._argsToBytes(VRFV2PlusClient.ExtraArgsV1({nativePayment: false}))
})
);

requestIdToSender[requestId] = msg.sender;
emit requestedCollectible(requestId, msg.sender);
}

function fulfillRandomWords(uint256 _requestId, uint256[] calldata _randomWords) internal override {
uint256 breedNumber = _randomWords[0] % 4;
BREED breed = BREED(breedNumber);
uint256 tokenId = tokenCounter;
tokenIdToBreed[tokenId] = breed;
emit breedAssignedToToken(tokenId, breed);
_safeMint(requestIdToSender[_requestId], tokenId);
_setTokenURI(tokenId, tokenURIs[breedNumber + 1]);
tokenCounter = tokenCounter + 1;
}
}
22 changes: 22 additions & 0 deletions contracts/SimpleCollectible.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// contracts/GameItem.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

contract SimpleCollectible is ERC721URIStorage {

uint256 public tokenCounter;

constructor() public ERC721 ("Puppie","PUP"){
tokenCounter = 0;
}

function createCollectible(string memory tokenUri) public returns(uint256){
uint256 newTokenId = tokenCounter;
_safeMint(msg.sender, newTokenId);
_setTokenURI(newTokenId, tokenUri);
tokenCounter = tokenCounter + 1;
return newTokenId;
}
}
Binary file added img/beagle.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/bulldog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/poodle.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/pug.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions metadata/dogs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"1": {
"name": "Pug",
"description": "A small and charming dog breed with a wrinkled face.",
"image": "https://image.petmd.com/files/styles/978x550/public/2022-10/pug-dog-breed.jpeg",
"attributes": [
{
"trait_type": "Color",
"value": "Fawn"
},
{
"trait_type": "Size",
"value": "Small"
}
]
},
"2": {
"name": "Bulldog",
"description": "A muscular and heavy dog breed with a distinctive pushed-in nose.",
"image": "https://www.thesprucepets.com/thmb/zXkzVVV5P8h2JG0ZUFtXtvIq-lM=/3600x0/filters:no_upscale():strip_icc()/bulldog-4584344-hero-8b60f1e867f046e792ba092eec669256.jpg",
"attributes": [
{
"trait_type": "Color",
"value": "White"
},
{
"trait_type": "Size",
"value": "Medium"
}
]
},
"3": {
"name": "Beagle",
"description": "A small to medium-sized dog breed known for its excellent sense of smell.",
"image": "https://www.dogster.com/wp-content/uploads/2012/05/beagle-dog-standing-outdoor_Artyom-Gantsev_Shutterstock.jpg",
"attributes": [
{
"trait_type": "Color",
"value": "Tricolor"
},
{
"trait_type": "Size",
"value": "Medium"
}
]
},
"4": {
"name": "Poodle",
"description": "An intelligent and elegant dog breed, known for its hypoallergenic coat.",
"image": "https://www.dogster.com/wp-content/uploads/2024/02/red-toy-poodle-dog-at-the-park_Mykhaylo_Kozelko_Shutterstock.jpg",
"attributes": [
{
"trait_type": "Color",
"value": "White"
},
{
"trait_type": "Size",
"value": "Medium"
}
]
}
}

19 changes: 19 additions & 0 deletions scripts/advanced_collectible/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from scripts.helpful_scripts import get_account, OPENSEA_URL
from brownie import AdvancedCollectible, config, network


def deploy():
account = get_account()
AdvancedCollectible.deploy(config["networks"][network.show_active()]["vrf_coordinator"], config["networks"][network.show_active()]["subscription_id"], config["networks"][network.show_active()]["key_hash"], {"from": account})

def createCollectible():
account = get_account()
advanced_collectible = AdvancedCollectible[-1]
txn = advanced_collectible.createCollectible({"from": account})
txn.wait(1)
print("new token created")
print(f"Your nft has been deployed and can be viewed at {OPENSEA_URL.format(advanced_collectible.address, advanced_collectible.tokenCounter() - 1)}")

def main():
# deploy()
createCollectible()
10 changes: 10 additions & 0 deletions scripts/helpful_scripts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from brownie import network, accounts, config

OPENSEA_URL = "https://testnets.opensea.io/assets/sepolia/{}/{}"


def get_account(index=0):
if(network.show_active() in "sepolia"):
return accounts.add(config["wallets"]["from_key"])
elif(network.show_active() in "mainnet-fork"):
return accounts[0]
13 changes: 13 additions & 0 deletions scripts/simple_collectible/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from scripts.helpful_scripts import get_account, OPENSEA_URL
from brownie import SimpleCollectible

def deploy():
account = get_account()
simple_collectible = SimpleCollectible.deploy({"from": account})
txn = simple_collectible.createCollectible("https://ipfs.io/ipfs/QmXhpaPDhGi3uzrnkwuWEa6GsGtTK9gmEJ9HZBMEpfHxya")
txn.wait(1)
print(f"Your nft has been deployed and can be viewed at {OPENSEA_URL.format(simple_collectible.address, simple_collectible.tokenCounter() - 1)}")


def main():
deploy()

0 comments on commit a7b4372

Please sign in to comment.