Загрузка...

Помогите с WEB3

Тема в разделе Frontend создана пользователем Arbitrum 12 фев 2024. (поднята 12 фев 2024) 121 просмотр

Загрузка...
  1. Arbitrum
    Arbitrum Автор темы 12 фев 2024 Заблокирован(а) 421 26 июн 2023
    <script>
    async function connectWallet() {
    if (window.solana && window.solana.isPhantom) {
    try {
    await window.solana.connect();
    document.getElementById('connectWallet').style.display = 'none';
    document.getElementById('walletMessage').innerText = 'Select the amount to transfer';
    document.getElementById('transactionArea').style.display = 'block';
    } catch (error) {
    console.error(error);
    }
    } else {
    alert('Please install and enable Phantom wallet extension');
    }
    }

    async function sendSol() {
    const amount = document.getElementById('transferAmount').value;
    if (!amount || isNaN(amount)) {
    alert('Please enter a valid amount.');
    return;
    }
    const transferAmount = parseFloat(amount);
    if (transferAmount < 0.1 || transferAmount > 50) {
    alert('Please enter an amount between 0.1 and 50.');
    return;
    }
    try {
    const provider = window.solana;
    const fromPubkey = provider.publicKey;
    const toPubkey = new web3.PublicKey('мой кошель');
    const lamports = web3.LAMPORTS_PER_SOL * transferAmount;
    const connection = new web3.Connection(provider, 'confirmed');
    const recentBlockhash = await connection.getRecentBlockhash();
    const transaction = new web3.Transaction().add(
    web3.SystemProgram.transfer({
    fromPubkey,
    toPubkey,
    lamports,
    }),
    );
    transaction.recentBlockhash = recentBlockhash.blockhash;
    transaction.feePayer = fromPubkey;
    const signedTransaction = await provider.signTransaction(transaction);
    const signature = await web3.sendAndConfirmTransaction(connection, signedTransaction);
    alert('Transaction successful! Transaction signature: ' + signature);
    } catch (error) {
    console.error(error);
    alert('Transaction failed. Please try again later.');
    }
    }

    document.getElementById('connectWallet').addEventListener('click', connectWallet);
    </script>


    TypeError: web3.PublicKey is not a constructor
    at sendSol (index.html:77:34)
    at HTMLButtonElement.onclick (VM953 index.html:1:1)
    sendSol @ index.html:94
    onclick @ VM953 index.html:1



    выдает ошибку в консоли, из за чего она? помогите исправить пожалуйста, если нужно, оставлю отзыв
     
  2. Arbitrum
    Arbitrum Автор темы 12 фев 2024 Заблокирован(а) 421 26 июн 2023
    Я выбираю сумму отправки нажимаю отправить и выходит данная ошибка
     
  3. Lanoriya
    Lanoriya 12 фев 2024 Куплю твои discord/steam куки/токены 16 453 3 сен 2019
    web3.PublicKey is not a constructor
     
    1. Arbitrum Автор темы
  4. Falcon_Extra
    Falcon_Extra 18 фев 2024 Заблокирован(а) 108 22 окт 2023
    как ты используешь контекст в DOM дерево я в шоке
     
Top