Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Get all NFTs in the NFT collection</title>
    <script type="module" src="./app.js"></script>
</head>
<body>
    <div id='form'>
        <h2>NFT Collection Address: </h2>
        <input type="text" id="address" placeholder="Enter collection address" value='0x48355CE6ba377D06335Be9499fEaf735948484BC'/>
        <button id="check-balance">Load Collection</button>
    </div>
    <div id="total-nfts"></div>
    <div id="balance-container"></div>

    <script type="module">
        document.addEventListener('DOMContentLoaded', (event) => {
            document.getElementById('check-balance').click();
        });
    </script>
</body>
</html>

              
            
!

CSS

              
                body {
  font-family: Poppins, sans-serif;
  background-color: white;
  font-size: 18px;
  color: #1C1E4F;
  text-align: left;
  margin-left: 20px;
}

input[type="text"] {
  width: 20%;
  padding: 13px 20px;
  font-size: 16px;
  border-radius: 5px;
  border: 1px solid #e4e4e4;
  margin-bottom: 20px;
}

#check-balance {
  font-family: Poppins, sans-serif;
  padding: 10px 20px;
  font-size: 18px;
  border-radius: 5px;
  border: 1px solid transparent;
  background-color: #4237ff;
  color: white;
  cursor: pointer;
  transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

#check-balance:hover {
  background-color: white;
  color: #4237ff;
  border-color: #4237ff;
}

#balance-container {
  margin-top: 20px;
  font-size: 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}

#balance-container div {
  flex: 0 0 24%;
  margin: 0.34em;
  box-sizing: border-box;
}

#balance-container img {
  width: 100%;
  height: auto;
}
              
            
!

JS

              
                import {TatumSDK, Network, Ethereum, ResponseDto, NftTokenDetail} from "https://esm.sh/@tatumio/tatum";

const button = document.getElementById("check-balance");
const addressInput = document.getElementById('address');
const balanceContainer = document.getElementById('balance-container');
const totalNFTs = document.getElementById('total-nfts');

button.addEventListener("click", async () => {
  const tatum = await TatumSDK.init<Ethereum>({ network: Network.ETHEREUM });
  const balance = await tatum.nft.getNftsInCollection({
    collectionAddress: [addressInput.value],
  });

  // Remove previous entries
  balanceContainer.innerHTML = '';
  
  // Display the total number of NFTs found
  totalNFTs.textContent = `Total Number of NFTs Found: ${balance.data.length}`;

  // Sort the array so NFTs without metadata images are at the end
  const sortedBalanceData = balance.data.sort((a, b) => (b.metadata && b.metadata.image) ? 1 : -1);

  // Create a new entry for each NFT
  sortedBalanceData.forEach(nft => {
    const entry = document.createElement('div');
    const image = document.createElement('img');
    const name = document.createElement('p');
    
    // Create a new Image object
    const imgObj = new Image();

    // Set a loading image
    image.src = 'https://loading.io/spinners/dual-ring/lg.dual-ring-loader.gif'; // Use any loading image or gif you prefer

    imgObj.onload = function() {
      // Once the image is loaded, replace the source of the image element
      image.src = imgObj.src;
    }

    imgObj.onerror = function() {
      // If there is an error loading the image, replace the source with the unavailable image
      image.src = 'https://user-images.githubusercontent.com/10515204/56117400-9a911800-5f85-11e9-878b-3f998609a6c8.jpg';
    }

    // If there is a metadata image, load the image
    if (nft.metadata && nft.metadata.image) {
      imgObj.src = nft.metadata.image;
    } else {
      // If there is no metadata image, set the image as not available
      image.src = 'https://user-images.githubusercontent.com/10515204/56117400-9a911800-5f85-11e9-878b-3f998609a6c8.jpg';
    }

    // If there is a metadata name, use it. Otherwise, use 'Name not given'
    name.textContent = nft.metadata && nft.metadata.name ? nft.metadata.name : 'Name not given';
    
    entry.appendChild(image);
    entry.appendChild(name);
    balanceContainer.appendChild(entry);
  });
});
              
            
!
999px

Console