mirror of
https://github.com/PatrickAlphaC/nft-mix.git
synced 2021-05-29 14:48:31 +03:00
updated for new dogs and auto setting tokenuri
This commit is contained in:
5
.env
5
.env
@@ -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
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
||||
build
|
||||
.pytest_cache
|
||||
.env
|
||||
.DS*
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
@@ -1 +0,0 @@
|
||||
{"name": "SHIBA_INU", "description": "An adorable SHIBA_INU pup!", "image": "https://ipfs.io/ipfs/QmSsYRx3LpDAb1GZQm7zZ1AuHZjfbPkD6J7s9r41xu1mf8?filename=pug.png", "attributes": [{"trait_type": "cuteness", "value": 100}]}
|
||||
11
metadata/rinkeby/2-ST_BERNARD.json
Normal file
11
metadata/rinkeby/2-ST_BERNARD.json
Normal file
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -10,15 +10,19 @@ from dotenv import load_dotenv
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -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(
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,14 +4,28 @@ from metadata import sample_metadata
|
||||
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):
|
||||
|
||||
@@ -2,7 +2,7 @@ from brownie import accounts, AdvancedCollectible, config, interface, network
|
||||
|
||||
|
||||
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]
|
||||
|
||||
|
||||
@@ -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}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user