Загрузка...

Help with WEB3

Thread in Frontend created by Arbitrum Feb 12, 2024. (bumped Feb 12, 2024) 133 views

  1. Arbitrum
    Arbitrum Topic starter Feb 12, 2024 Banned 421 Jun 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 Topic starter Feb 12, 2024 Banned 421 Jun 26, 2023
    Я выбираю сумму отправки нажимаю отправить и выходит данная ошибка
     
  3. Lanoriya
    Lanoriya Feb 12, 2024 Куплю твои discord/steam куки/токены 16,580 Sep 3, 2019
    web3.PublicKey is not a constructor
     
    1. Arbitrum Topic starter
  4. Falcon_Extra
    Falcon_Extra Feb 18, 2024 Banned 108 Oct 22, 2023
    как ты используешь контекст в DOM дерево я в шоке
     
Loading...
Top