DEV Community

Discussion on: NFT images generator using Python Jupyter Notebook

Collapse
victorquanlam profile image
Victor Quan Lam Author • Edited on

Hi Chris! Great questions.

How would I upload these to Opensea?
This is another blog of mine which will show you how to upload images to Opensea.
dev.to/victorquanlam/step-by-step-...

What do I do with the Png and the Json metadata? Do I need to upload both files to somewhere?
Yes you need to create new shapes folder and upload your png images there and you don't have to upload the Json metadata. It already be generated by the script below:

METADATA_FILE_NAME = './metadata/all-traits.json'; 
with open(METADATA_FILE_NAME, 'w') as outfile:
    json.dump(all_images, outfile, indent=4)
Enter fullscreen mode Exit fullscreen mode


`

Furthermore, if I am creating a collection of 5,000 NFTs is there an automated way to upload each file to Opensea?
Yes and no. As right now, the opensea api doesn't support upload images YET. We will need to wait for the next version. This is their comment to the situation: "there isn't currently an option for that in your OpenSea profile, but we're constantly working on ways to improve user experience".

image

The only way for now is to create your own smart contract most likely on ETH chain. Then upload your images to IPFS server and connect your contract to opeasea. (I know! Yikes)

Collapse
chris_t_3ecc33da3626748cd profile image
Chris T • Edited on

Thanks for your quick reply! :)

In response to my 2nd question, the Metadata will already be already included within the PNG files from that line of code you show? So I could just upload the image created onto Opensea and the metadata will also be uploaded too?

Ah okay! Still trying to wrap my head around the smart contracts, a lot more complicated than uploading each file one by one on Opensea :S

Thread Thread
victorquanlam profile image
Victor Quan Lam Author • Edited on

image here

As you can see the metadata files will be generated under the metadata folder.
image here

You can run this little javascript to update the meta data

const fetch = require('node-fetch');

// Update [ADD_CONTRACT_ADDRESS] to your Contract Address
const OPENSEA_URI = 'https://api.opensea.io/asset/ADD_CONTRACT_ADDRESS'; 

// Maximum Tokens Belonging to Contract
const MAX_TOKENS = 3349;


// update OPENSEA_URI
function refreshData(tokenId) {
    const URI = `${OPENSEA_URI}/${tokenId}/?force_update=true`;
    const OPTIONS = {method: 'GET'};

    fetch(URI, OPTIONS)
    .then(res => res.json())
    .then(json =>  {
        if(json.detail) {
            console.log(`failed: ${tokenId}`);
        } else if(json.token_id) {
            console.log(`success: ${tokenId}`);
        }
    })
    .catch(err => console.error(`failed: ${tokenId}`));
};


const refreshTokens = (start, end) => {
    Array.from({length: end - start + 1}, (x, i) => start + i).forEach((tokenId) => {    
        refreshData(tokenId);
    });   
}

let start = 0;
let end = 1;

const id = setInterval(() => { 
    refreshTokens(start, end);
    if(end > MAX_TOKENS) clearInterval(id);
    start = end + 1;
    end = start + 1;
},2000);

Enter fullscreen mode Exit fullscreen mode


`
Check this article out for more details about metadata
docs.opensea.io/docs/2-adding-meta...

Hope it helps.

Thread Thread
chris_t_3ecc33da3626748cd profile image
Chris T

Great thanks!

Sorry to keep asking questions! There is a lot to learn.

What do I put in here:

IMAGES_BASE_URI = "ADD_IMAGES_BASE_URI_HERE"

I'm still a little confused as to what to do after creating the PNG and Metadata files. Do I need to upload these onto IPFS and then upload that to Opensea? Or if I upload the PNG files directly to Opensea it would automatically do it for me?

Thread Thread
victorquanlam profile image
Victor Quan Lam Author • Edited on

This is where you store your images for public views. It can be used when creating your smart contract.

Hope this gives you enough hint. I'm working on a web app to generate pixelated nft arts at the moment so I don't have much time to explain things in much details. I would create a new blog post for creating ERC721 Token and nft in the near future.