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

              
                <body>
  <img src="https://theme.zdassets.com/theme_assets/10342982/b874f2d764307e820514e17252b783f0f344ede6.svg">
  <h1>Rarible API: NFT owned by user</h1>
  <select id="rpcSelector">
    <option value="https://testnet-api.rarible.org/v0.1/items/byOwner?blockchains=ASTARZKEVM">zKyoto (testnet)</option>

    <option value="https://api.rarible.org/v0.1/items/byOwner?blockchains=ASTARZKEVM">Astar zkEVM (mainnet)</option>
  </select>
  <input type="text" id="hexInput" placeholder="User address 0x...">
  <input type="text" id="raribleApiKey" placeholder="Rarible API key 11111111-1111-1111-1111-111111111111">
  <p>Get free Rarible API key <a href="https://api.rarible.org/dashboard/login" target="_blank">here</a></p>

  <button onclick="RaribleInfo()">Fetch NFTS</button>
  <p id="error-message" style="display: none; color: red;"></p>
  <div style="overflow: auto; height: 300px;">

    <table id="infoTable">
      <thead>
        <tr>
          <th>Collection</th>
          <th>TokenId</th>
          <th>Supply</th>
          <th>Name</th>
        </tr>
      </thead>
      <tbody>
      </tbody>
    </table>
  </div>
</body>
              
            
!

CSS

              
                body {
  font-family: system-ui;
  background: #feda03;
  color: black;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 70vh;
  flex-direction: column;
  overflow: auto;
}
h1,
table {
  display: block;
  width: 100%;
}
#infoTable {
  margin-top: 20px;
  border-collapse: collapse;
  width: 100%;
}

#infoTable th {
  background-color: black;
  color: white;
  padding: 10px;
  text-align: left;
}

#infoTable td {
  border: 1px solid #ddd;
  padding: 8px;
}

option {
  background-color: #fff;
  color: #000;
  padding: 10px;
  margin-top: 20px;
  font-size: 16px; /* Adjust as needed */
}

button {
  background-color: #000;
  margin-top: 20px;
  color: #fff;
  border: none;
  border-radius: 5px; /* This will make the button have rounded corners */
  padding: 10px 20px;
  cursor: pointer;
}

input[type="text"] {
  padding: 10px;
  border: 1px solid #000;
}

#hexInput {
  margin-top: 20px;
  width: 50%;
  padding: 10px;
  font-size: 16px;
}

#raribleApiKey {
  margin-top: 20px;
  width: 50%;
  padding: 10px;
  font-size: 16px;
}
select {
  padding: 5px; /* Adjust as needed */
  font-size: 16px; /* Adjust as needed */
}

img {
  position: absolute;
  top: 0;
  left: 0;
}

.error-message {
  color: red;
}

              
            
!

JS

              
                async function RaribleInfo() {
  var tbody = document
    .getElementById("infoTable")
    .getElementsByTagName("tbody")[0];
  // Clear the table body
  while (tbody.firstChild) {
    tbody.removeChild(tbody.firstChild);
  }
  const selectedRpc = document.getElementById("rpcSelector").value;
  const address = document.getElementById("hexInput").value;
  let raribleApiKey = document.getElementById("raribleApiKey").value;
  if (raribleApiKey === "") {
    raribleApiKey = "11111111-1111-1111-1111-111111111111";
  }
  console.log("key", raribleApiKey);
  const headers = {
    "X-Api-Key": `${raribleApiKey}`,
    "Content-Type": "application/json",
    Referer: "https://docs.rarible.org"
  };

  const url = `${selectedRpc}&owner=ETHEREUM%3A${address}`;
  console.log("url: ", url);
  console.log("header: ", headers);
  fetch(url, {
    method: "GET",
    headers: headers
  })
    .then((response) => {
      if (!response.ok) {
        // if HTTP status is not ok
        throw new Error(`HTTP error! status: ${response.status}`);
      }
      return response.json();
    })
    .then((data) => {
      console.log("data: ", data);
      const tableBody = document.querySelector("#infoTable tbody");
      data.items.forEach((item) => {
        const row = document.createElement("tr");
        row.innerHTML = `
            <td>${item.collection.split(":")[1]}</td>
            <td>${item.tokenId}</td>
            <td>${item.supply}</td>
            <td>${item.itemCollection.name}</td>
          `;
        tableBody.appendChild(row);
      });
    })
    .catch((error) => {
      console.error("Error message:", error.message);
      console.error("Stack trace:", error.stack);

      const errorMessageElement = document.getElementById("error-message");
      errorMessageElement.textContent = `Error: ${error.message || ""}`;
      errorMessageElement.style.display = "block";
    });
}

              
            
!
999px

Console