简体   繁体   English

如何从 OpenSea 实时获取数据?

[英]How can I fetch data from OpenSea in real time?

I built a simple web application that outputs an "NFT wallet" from opensea based on the wallet address I input.我构建了一个简单的 web 应用程序,它根据我输入的钱包地址从 opensea 输出一个“NFT 钱包”。

Now lets say a transaction occur and the owner of the wallet sold or bought an nft, how can I update my web application in real time?现在假设发生交易并且钱包的所有者出售或购买了一个 nft,我如何实时更新我的 web 应用程序?

in other words how can I listen for changes in a wallet from the api and output them in real time?换句话说,我如何实时监听来自 api 和 output 的钱包变化?

app.js:应用程序.js:

async function getNFT(address) {
    const response = await fetch("https://api.opensea.io/api/v1/assets?owner=" + address + "&order_direction=desc&offset=0&limit=20");
    const data = await response.json();
    console.log(data);
    let NFTWallet = [];
    for (const asset of data.assets) {
        const NFT = {
            url: asset.image_url,
            name: asset.asset_contract.name
        }
        NFTWallet.push(NFT);
        let nft = document.createElement("span");
        let image = document.createElement("span");
        image.innerHTML = "<img src='" + NFT.url + "' width=\"84px\" height=\"84px\" title=\"" + NFT.name + "\"/>";
        nft.appendChild(image);
        document.getElementById("nft-wallet").appendChild(nft);
    }
    console.log(NFTWallet);
}

window.addEventListener("load", getNFT("wallet-adress"));//input wallet in getNft()

index.html:索引.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>OpenSea Connection</title>
    <script src="app.js"></script>
</head>
<body>
    <h1>NFT Wallet</h1>
    <div id="nft-wallet"></div>
</body>
</html>

You need to store the results of the first response from the function getNFT locally for example using Window.localStorage, and use setInterval() to call again the function getNFT with a delay in between executions and compare the results with the previous values. You need to store the results of the first response from the function getNFT locally for example using Window.localStorage, and use setInterval() to call again the function getNFT with a delay in between executions and compare the results with the previous values.

Window.localStorage Window.localStorage

setInterval()设置间隔()

Any answer to this?对此有什么答案吗? i'm interested我很感兴趣

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 API 获取数据,其中 stream 实时数据 - How to fetch data from an API which stream real time data 我如何以更有效和更少错误的方式获取实时json数据? - How can I fetch the real-time json data in more efficient and less buggy way? 如何获取 OpenSea API - How To Fetch OpenSea API 如何使用云函数从我的 Firebase 实时数据库中 database.ref 正在侦听的节点内部获取数据? - How can I fetch data from inside a node which the database.ref is listening to in my Firebase real-time database using cloud functions? 如何从服务器实时获取数据以更新Chartjs图形? - How can i get data in real time from the server to update my chartjs graph? 如何获取 Json 数据到实时更新 Html 表? - how to fetch Json Data to real Time updating Html Table? 如何使用 OpenSea JavaScript SDK 解决 404 问题? - How can I solve 404 issue using the OpenSea JavaScript SDK? 如何从 Firebase 获取数据到我的 React 应用程序中 - How can I fetch data from Firebase into my React App 如何从服务器/数据库中获取自动建议文本框中的数据? - How can I fetch data in autosuggest textbox from server/database? 如何在 React 中从 Websocket 获取数据? - How can I fetch data from a Websocket in React?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM