[英]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.
Any answer to this?对此有什么答案吗? i'm interested我很感兴趣
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.