anza-xyz / wallet-adapter

Modular TypeScript wallet adapters and components for Solana applications.
https://anza-xyz.github.io/wallet-adapter/
Apache License 2.0
1.59k stars 960 forks source link

Coinabase Wallet transaction on Solana DevNet is failing #1009

Open kkatusic opened 2 months ago

kkatusic commented 2 months ago

Describe the bug

If you want to use Coinbase wallet to test transaction on Solana Devnet network you can't. No errors in console.

To Reproduce

Steps to reproduce the behavior:

  1. Open your Chrome browser
  2. Login to the Coinabase wallet
  3. Go to link: https://next-js-vercel-pi.vercel.app/solana
  4. Add recipient solana address
  5. Add small amount of the Solana devnet token
  6. Click on button "Do test transaction to...."
  7. You will see Coinbase popup with content like on image bellow

Expected behavior

It should ask you to confirm transaction and execute same on Solana devnet network

Screenshots

Screenshot 2024-08-20 at 14 49 26

Desktop (please complete the following information):

Additional context

I will provide here test code, this is component inside NextJS.:

"use client";

import dynamic from "next/dynamic";
import {
  PublicKey,
  SystemProgram,
  Transaction,
  LAMPORTS_PER_SOL,
} from "@solana/web3.js";
import { useConnection, useWallet } from "@solana/wallet-adapter-react";
import { WalletNotConnectedError } from "@solana/wallet-adapter-base";

import { useCallback, useState } from "react";

const MakeTestSolanaTransaction = () => {
  const { connection } = useConnection();
  const { publicKey, sendTransaction } = useWallet();
  const [recipientPublicKey, setRecipientPublicKey] = useState(
    new PublicKey("CASBXtuVK8WdNByaVaDfB1PGptMM7bJoVAjAuR2nWLNL")
  );

  const [solAmount, setSolAmount] = useState(0.001); // Default to 0.001 SOL

  const createTestSolanaTransaction = useCallback(async () => {
    if (!publicKey) throw new WalletNotConnectedError();
    if (!recipientPublicKey) {
      console.warn("No generated public key available. Generate one first.");
      return;
    }

    const transaction = new Transaction().add(
      SystemProgram.transfer({
        fromPubkey: publicKey,
        toPubkey: recipientPublicKey,
        lamports: solAmount * LAMPORTS_PER_SOL,
      })
    );

    // Define feePayer if it doesn't exist
    if (!transaction.feePayer) {
      transaction.feePayer = publicKey;
    }

    const simulationResult = await connection.simulateTransaction(transaction);

    console.log("Simulation Result:", simulationResult);

    if (simulationResult.value.err) {
      console.error("Simulation error:", simulationResult.value.err);
      return;
    }

    // Send the transaction
    try {
      const signature = await sendTransaction(transaction, connection);
      console.log("Transaction signature:", signature);

      // Optionally confirm the transaction
      await connection.confirmTransaction(signature, "confirmed");
      console.log("Transaction confirmed");
    } catch (error) {
      console.error("Transaction failed", error);
    }
  }, [publicKey, sendTransaction, connection, recipientPublicKey]);

  return (
    <>
      <h3 className="mb-4 text-4xl pb-12">Try to send 0,001 SOL on Devnet</h3>
      <div className="mb-12 w-2/4">
        <label className="block text-lg font-medium text-center">
          Recipient Address
        </label>
        <input
          type="text"
          value={recipientPublicKey.toString()}
          onChange={(e) => setRecipientPublicKey(new PublicKey(e.target.value))}
          className="w-full p-2 mt-1 border rounded"
          placeholder="Enter recipient's public key"
        />
      </div>

      <div className="mb-12">
        <label className="block text-lg font-medium text-center">
          Amount (SOL)
        </label>
        <input
          type="number"
          value={solAmount}
          onChange={(e) => setSolAmount(parseFloat(e.target.value))}
          className="w-full p-2 mt-1 border rounded"
          placeholder="Enter amount in SOL"
          min="0.001"
          step="0.001"
        />
      </div>
      <button
        onClick={createTestSolanaTransaction}
        className="p-4 bg-pink-700 text-white text-xl rounded"
      >
        Do test transaction to {recipientPublicKey.toString()} (0.001 SOL)
      </button>
    </>
  );
};

export default MakeTestSolanaTransaction;

this is solana provider:

"use client";

import React, { useMemo } from "react";
import {
  ConnectionProvider,
  WalletProvider,
} from "@solana/wallet-adapter-react";
import { WalletAdapterNetwork } from "@solana/wallet-adapter-base";
import { WalletModalProvider } from "@solana/wallet-adapter-react-ui";
import { clusterApiUrl } from "@solana/web3.js";
import {
  CoinbaseWalletAdapter,
  TrustWalletAdapter,
} from "@solana/wallet-adapter-wallets";

// Default styles that can be overridden by your app
require("@solana/wallet-adapter-react-ui/styles.css");

export default function AppWalletProvider({
  children,
}: {
  children: React.ReactNode;
}) {
  const network = WalletAdapterNetwork.Devnet;
  const endpoint = useMemo(() => clusterApiUrl(network), [network]);
  const wallets = useMemo(
    () => [
      new CoinbaseWalletAdapter({ network }),
      new TrustWalletAdapter({ network }),
    ],
    [network]
  );

  return (
    <ConnectionProvider endpoint={endpoint}>
      <WalletProvider wallets={wallets} autoConnect>
        <WalletModalProvider>{children}</WalletModalProvider>
      </WalletProvider>
    </ConnectionProvider>
  );
}
Luchanso commented 2 months ago

the same problem

Luchanso commented 2 months ago

this is solflare wallet problem - on other everything okey

kkatusic commented 1 month ago

this is solflare wallet problem - on other everything okey

You mean this is problem inside Coinbase wallet?

Luchanso commented 1 month ago

I have the same problem, but with solflare wallet issue