DEV Community

Discussion on: NFT images generator using Python Jupyter Notebook

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.