lorisleiva / solana-wallets-vue

Solana wallet integration for Vue 3
https://solana-wallets-vue-demo.netlify.app/
173 stars 64 forks source link

signTransaction() not worked, error as "WalletSignTransactionError: Expected String" #29

Open jackalchenxu opened 2 years ago

jackalchenxu commented 2 years ago

Hello, lorisleiva, thanks for your great work.

i'm now trying use solana-wallets-vue with Vue3 and make a simple test, like the sample code; wallet software is Phantom, installed as Chrome plugin; wallet is changed to use your lib.

the sample code is like below:

import { useWallet }  from `solana-wallets-vue`;
import { Connection, Transaction } from `@solana/web3.js`;
...
const { wallet, publicKey }  = useWallet();
...
let transaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: wallet.publicKey,
    toPubkey: wallet.publicKey,
    lamports: 100,
  })
);
let { blockhash } = await connection.getRecentBlockhash();
transaction.recentBlockhash = blockhash;
transaction.feePayer = wallet.publicKey;
let signed = await wallet.signTransaction(transaction);
let txid = await connection.sendRawTransaction(signed.serialize());
await connection.confirmTransaction(txid);

the error occurs at let signed = await wallet.signTransaction(transaction);, the error message as: WalletSignTransactionError: Expected String at PhantomWalletAdatapter,signTransaction

i trace the code, and under the hood, the code shows wallet need its secretkey to sign a transaction, but all know, the wallet doesn't expose the secretkey.

if we change the above sample code, not sign the transaction, but directly sendTransaction(...), it will work! (sendTransaction will still partialsignTransaction, but in itself inner implementation of wallet code)

Here is my question:

if you need the full code to reproduce the issue , please comment.

Psionyc commented 2 years ago

Recently there have been lots of errors on the phantom side of solana. While using wallet.sendTransaction() it shows "Missing or Invalid Parameters" with a long stack trace leading back to solana-wallets-vue... I feel this is related so I decided to drop it here....

And I tried the adapters on react and it worked so...

Aanhane commented 2 years ago

Yep facing the same issue here. I've tried updating the dependencies but without a guide on how to contribute to the project, it's hard. I'm unable to test the package properly, as I also can't get a fork to simply compile.

Psionyc commented 2 years ago

So after trying somethings I found out wallet.signTransaction.value works and the transaction is signed for all wallets... While checking why the error might have occured with wallet.sendTransaction I found out that in the phantom wallet adapter code the function is named signAndSendTransaction() which might be the overall cause of the error...

hsienfu commented 2 years ago

Maybe the SendOptions is required for wallet.sendTransaction method. Initialize connection with commitmentOrConfig works. const connection = new Connection(clusterApiUrl('devnet'), 'confirmed').