首页 > 解决方案 > 将字符串从 javascript 中的变量添加到 HTML 中的 API URL

问题描述

所以我试图将来自 MetaMask 的以太坊地址包含到 Opensea API 中。

用户钱包地址保存在 userWalletAddress

            async function LoginWithMetaMask () {
            const accounts = await window.ethereum.request({ method: 
            'eth_requestAccounts' })
                .catch((e) => {
                    console.error(e.message)
                    return
                })
            if (!accounts) { return }

            window.userWalletAddress = accounts[0]
            userWallet.innerText = window.userWalletAddress
            loginButton.innerText = 'Sign out of MetaMask'

我现在想将地址添加到显示/嵌入来自 OpenSea 的 API 的用户 NFT 的 URL。我该怎么做呢?我希望 URL 中的“userWallet”是存储在 window.userWalletAddress 中的地址

        <iframe src='https://opensea.io/userWalletAddress?embed=true'
        width='50%'
        height='50%'
        frameborder='0'
        allowfullscreen></iframe>

标签: javascripthtmlapi

解决方案


推荐阅读