Skip to content

Commit

Permalink
updated for new dogs and auto setting tokenuri
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickAlphaC committed Apr 10, 2021
1 parent 48486ab commit 0468459
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
### remove the '#' to use the environment variables
# export PRIVATE_KEY=asafdagadd
# export WEB3_INFURA_PROJECT_ID=asdfsdf


### Optional - don't uncomment if you don't know what they do!
# export ETHERSCAN_TOKEN=asdfasdfasdf
# export IPFS_URL=http://127.0.0.1:5001
# export UPLOAD_IPFS=true
# export WEB3_INFURA_PROJECT_ID=asdfsdf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
build
.pytest_cache
.env
.DS*

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ There are 2 types of NFTs here.
1. `SimpleCollectibles.sol`
2. `AdvancedCollectibles.sol`

They each deploy unique dogs. The advanced version gives you a random breed (out of a Pug, Shiba Inu, and St. Brenard).
They each deploy unique dogs. The advanced version gives you a random breed (out of a Pug, Shiba Inu, and St. Bernard).

The advanced collection uses a [Chainlink VRF](https://docs.chain.link/docs/get-a-random-number) to deploy the random dog.

Expand Down
4 changes: 2 additions & 2 deletions contracts/AdvancedCollectible.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol";

contract AdvancedCollectible is ERC721, VRFConsumerBase {
uint256 public tokenCounter;
enum Breed{PUG, SHIBA_INU, BRENARD}
enum Breed{PUG, SHIBA_INU, ST_BERNARD}
// add other things
mapping(bytes32 => address) public requestIdToSender;
mapping(bytes32 => string) public requestIdToTokenURI;
Expand All @@ -16,7 +16,7 @@ contract AdvancedCollectible is ERC721, VRFConsumerBase {

bytes32 internal keyHash;
uint256 internal fee;
uint256 public randomResult;

constructor(address _VRFCoordinator, address _LinkToken, bytes32 _keyhash)
public
VRFConsumerBase(_VRFCoordinator, _LinkToken)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "SHIBA_INU",
"name": "PUG",
"description": "An adorable SHIBA_INU pup!",
"image": "https://ipfs.io/ipfs/QmSsYRx3LpDAb1GZQm7zZ1AuHZjfbPkD6J7s9r41xu1mf8?filename=pug.png",
"image": "https://ipfs.io/ipfs/QmYx6GsYAKnNzZ9A6NvEKV9nf1VaDzJrqDR23Y8YSkebLU?filename=shiba-inu.png",
"attributes": [
{
"trait_type": "cuteness",
Expand Down
1 change: 0 additions & 1 deletion metadata/rinkeby/2-SHIBA_INU.json

This file was deleted.

11 changes: 11 additions & 0 deletions metadata/rinkeby/2-ST_BERNARD.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "ST_BERNARD",
"description": "An adorable ST_BERNARD pup!",
"image": "https://ipfs.io/ipfs/QmUPjADFGEKmfohdTaNcWhp7VGk26h5jXDA7v3VtTnTLcW?filename=st-bernard.png",
"attributes": [
{
"trait_type": "cuteness",
"value": 100
}
]
}
26 changes: 17 additions & 9 deletions scripts/advanced_collectible/create_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@

load_dotenv()


pug_uri = "https://ipfs.io/ipfs/QmSsYRx3LpDAb1GZQm7zZ1AuHZjfbPkD6J7s9r41xu1mf8?filename=pug.png"
breed_to_image_uri = {
'PUG': "https://ipfs.io/ipfs/QmSsYRx3LpDAb1GZQm7zZ1AuHZjfbPkD6J7s9r41xu1mf8?filename=pug.png",
'SHIBA_INU': "https://ipfs.io/ipfs/QmYx6GsYAKnNzZ9A6NvEKV9nf1VaDzJrqDR23Y8YSkebLU?filename=shiba-inu.png",
'ST_BERNARD': "https://ipfs.io/ipfs/QmUPjADFGEKmfohdTaNcWhp7VGk26h5jXDA7v3VtTnTLcW?filename=st-bernard.png"
}


def main():
print("Working on " + network.show_active())
advanced_collectible = AdvancedCollectible[len(AdvancedCollectible) - 1]
number_of_advanced_collectibles = advanced_collectible.tokenCounter()
print(number_of_advanced_collectibles)
print("The number of tokens you've deployed is: " +
str(number_of_advanced_collectibles))
write_metadata(number_of_advanced_collectibles, advanced_collectible)


Expand All @@ -35,9 +39,9 @@ def write_metadata(token_ids, nft_contract):
)
if Path(metadata_file_name).exists():
print(
"{} already found, delete it to overwrite!".format(metadata_file_name)
"{} already found, delete it to overwrite!".format(
metadata_file_name)
)
continue
else:
print("Creating Metadata file: " + metadata_file_name)
collectible_metadata["name"] = get_breed(
Expand All @@ -46,9 +50,11 @@ def write_metadata(token_ids, nft_contract):
collectible_metadata["description"] = "An adorable {} pup!".format(
collectible_metadata["name"]
)
image_to_upload = None
if os.getenv("UPLOAD_IPFS") == "true":
pug_uri = upload_nft()
collectible_metadata["image"] = pug_uri
image_to_upload = upload_nft()
image_to_upload = breed_to_image_uri[breed] if not image_to_upload else image_to_upload
collectible_metadata["image"] = image_to_upload
file = open(metadata_file_name, "w")
json.dump(collectible_metadata, file)

Expand All @@ -61,9 +67,11 @@ def upload_nft(image_path="./img/pug.png"):
if os.getenv("IPFS_URL")
else "https://ipfs.infura.io:5001/"
)
response = requests.post(ipfs_url + "/api/v0/add", files={"file": image_binary})
response = requests.post(ipfs_url + "/api/v0/add",
files={"file": image_binary})
ipfs_hash = response.json()["Hash"]
filename = image_path.split("/")[-1:][0]
image_uri = "https://ipfs.io/ipfs/{}?filename={}".format(ipfs_hash, filename)
image_uri = "https://ipfs.io/ipfs/{}?filename={}".format(
ipfs_hash, filename)
print(image_uri)
return image_uri
20 changes: 17 additions & 3 deletions scripts/advanced_collectible/set_tokenuri.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,28 @@
from scripts.helpful_scripts import get_breed


PUG_METADATA = "https://ipfs.io/ipfs/Qmd9MCGtdVz2miNumBHDbvj8bigSgTwnr4SbyH6DNnpWdt?filename=1-PUG.json"
dog_metadata_dic = {
'PUG': "https://ipfs.io/ipfs/Qmd9MCGtdVz2miNumBHDbvj8bigSgTwnr4SbyH6DNnpWdt?filename=0-PUG.json",
'SHIBA_INU': "https://ipfs.io/ipfs/QmQbvDdVXKc5FyTaiYaCsvHAzroF7d6Fa8fGtEBYvPMtrk?filename=1-SHIBA_INU.json",
'ST_BERNARD': "https://ipfs.io/ipfs/QmbBnUjyHHN7Ytq9xDsYF9sucZdDJLRkWz7vnZfrjMXMxs?filename=2-ST_BERNARD.json"
}
OPENSEA_FORMAT = "https://testnets.opensea.io/assets/{}/{}"


def main():
print("Working on " + network.show_active())
advanced_collectible = AdvancedCollectible[len(SimpleCollectible) - 1]
set_tokenURI(0, advanced_collectible, PUG_METADATA)
advanced_collectible = AdvancedCollectible[len(AdvancedCollectible) - 1]
number_of_advanced_collectibles = advanced_collectible.tokenCounter()
print("The number of tokens you've deployed is: " +
str(number_of_advanced_collectibles))
for token_id in range(number_of_advanced_collectibles):
breed = get_breed(advanced_collectible.tokenIdToBreed(token_id))
if not advanced_collectible.tokenURI(token_id).startswith("https://"):
print("Setting tokenURI of {}".format(token_id))
set_tokenURI(token_id, advanced_collectible,
dog_metadata_dic[breed])
else:
print("Skipping {}, we already set that tokenURI!".format(token_id))


def set_tokenURI(token_id, nft_contract, tokenURI):
Expand Down
5 changes: 3 additions & 2 deletions scripts/helpful_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def get_breed(breed_number):
switch = {0: "PUG", 1: "SHIBA_INU", 2: "BRENARD"}
switch = {0: "PUG", 1: "SHIBA_INU", 2: "ST_BERNARD"}
return switch[breed_number]


Expand All @@ -12,5 +12,6 @@ def fund_advanced_collectible(nft_contract):
interface.LinkTokenInterface(
config["networks"][network.show_active()]["link_token"]
).transfer(
nft_contract, config["networks"][network.show_active()]["fee"], {"from": dev}
nft_contract, config["networks"][network.show_active()]["fee"], {
"from": dev}
)

0 comments on commit 0468459

Please sign in to comment.