1

I connected the wallet to my test site, enter the amount for the test payment and click the button, after which a window is displayed and confirmation where it says "That the confirmation period has expired" how to fix it?

Phantom wallet

My code

<script>
    var wallet;
    const lamports_per_sol = solanaWeb3.LAMPORTS_PER_SOL;
    async function connectWallet() {
if (window.solana) {
    try {
        wallet = await window.solana.connect();
    } catch (err) {
        console.log(err);
    }
    window.solana.on(
        "connect",
        () => (
            document.getElementById("connect_button").innerText = "Connected",
            document.getElementById("walletMessage").style.display = "none"
        )
    );
} else if (window.Trust) {
    try {
        wallet = new Trust.Web3Provider();
        await wallet.enable();
    } catch (err) {
        console.log(err);
    }
} else {
    console.log("No wallet provider detected.");
}

}

    async function sendButtonClick() {
      const receiverAddress = "5AZbfDTE4ZrdBpyZrWdzB5u8VeZQyRiKVBXzmcKCKUzJ"

      const quantity = document.getElementById("quantity").value
      if (quantity != null && quantity != 0) {
        document.getElementById("status_p").text = "Status";
        document.getElementById("status_p").innerText = "Sending " + quantity + " SOL to " + ellipsizeAddress(receiverAddress) + " account address";
        await signInTransactionAndSendMoney(receiverAddress, quantity)
      } else {
        document.getElementById("status_p").text = "Status";
        document.getElementById("status_p").innerText = "Amount must be more than 0!"
      }

    }

    function ellipsizeAddress(str) {
      if (str.length > 35) {
        return str.substr(0, 8) + '...' + str.substr(str.length - 8, str.length);
      }
      return str;
    }

    function signInTransactionAndSendMoney(destPubkeyStr, quantity) {
      (async () => {
        const network = "https://api.devnet.solana.com";
        const connection = new solanaWeb3.Connection(network);
        const transaction = new solanaWeb3.Transaction();

        try {
          const lamports = quantity * lamports_per_sol;

          console.log("starting sendMoney");
          const destPubkey = new solanaWeb3.PublicKey(destPubkeyStr);
          const walletAccountInfo = await connection.getAccountInfo(
            wallet.publicKey
          );
          console.log("wallet data size", walletAccountInfo?.data.length);

          const receiverAccountInfo = await connection.getAccountInfo(
            destPubkey
          );
          console.log("receiver data size", receiverAccountInfo?.data.length);

          const instruction = solanaWeb3.SystemProgram.transfer({
            fromPubkey: wallet.publicKey,
            toPubkey: destPubkey,
            lamports,
          });
          let trans = await setWalletTransaction(instruction, connection);

          let signature = await signAndSendTransaction(
            wallet,
            trans,
            connection
          );

        } catch (e) {
          console.warn("Failed", e);
        }

      })();

      async function setWalletTransaction(instruction, connection) {
        const transaction = new solanaWeb3.Transaction();
        transaction.add(instruction);
        transaction.feePayer = wallet.publicKey;
        let hash = await connection.getRecentBlockhash();
        console.log("blockhash", hash);
        transaction.recentBlockhash = hash.blockhash;
        return transaction;
      }

      async function signAndSendTransaction(wallet, transaction, connection) {
        const { signature } = await window.solana.signAndSendTransaction(
          transaction
        );
        await connection.confirmTransaction(signature);
        return signature;
      }
    }

    </script>

1 Answer 1

1

Make sure that your wallet is connected to the same cluster as your application.

If your wallet is connected to Mainnet and your app to Testnet it will cause issues like these.

8
  • I dont enable testnet, i have 5$ on my phantom wallet , and i try to send this 5$ to my friend, and this error
    – yupigs
    Feb 12 at 20:33
  • i try send this money from my site
    – yupigs
    Feb 12 at 20:36
  • Well, your code states you are connected to Devnet (const network = "https://api.devnet.solana.com") so if you want to send it on Mainnet, make sure you update the endpoint in your code.
    – beeman
    Feb 13 at 0:27
  • What network for not dev
    – yupigs
    Feb 13 at 9:51
  • Failed to load resource: the server responded with a status of 403 () index.html:140 Failed Error: failed to get info about account HPFpsvyxaY2fzYxXsp7L3vQi5J4hKbhMSoryYrQHjqP7: Error: 403 : {"jsonrpc":"2.0","error":{"code": 403, "message":"Access forbidden, contact your app developer or [email protected]."}, "id": "4c044eae-6cc6-4afa-9d69-ab7266f3dd2a" } at Connection.getAccountInfo (connection.ts:2546:13) at async index.html:116:41 and i have error
    – yupigs
    Feb 13 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.