WalletConnectFlutterV2 icon indicating copy to clipboard operation
WalletConnectFlutterV2 copied to clipboard

solana_signTransaction error Unknown method(s) requested)

Open AmjadKhan2k18 opened this issue 2 years ago • 3 comments

I am trying to signTransaction on solana chain but get error JsonRpcError(code: 5201, message: Unknown method(s) requested) I guess Params aren't right

is there any example in flutter of signing transaction on solana/tron/bitcoin/doge/Ripple and send it to blockchain? I have been looking for example that's done with walletconnect but couldn't find any full example same as https://react-app.walletconnect.com/

AmjadKhan2k18 avatar Aug 21 '23 21:08 AmjadKhan2k18

Unknown methods means the request had a method that wasn't supported by the wallet.

I don't have a solana/tron/bitcoin/doge/Ripple example, no. Sorry.

The structure of the request will be the same between the site you referenced and flutter. I would recommend figuring out how they send requests and just copy them and paste your answer here so I can add it to my example.

Luzzotica avatar Aug 23 '23 02:08 Luzzotica

@Luzzotica I used solana_signTransaction method which is from WalletConnect documentation, I think if the params aren't match and any required data is missing TrustWallet throw this error I have seen this before

here is source code of project how they sign transaction on solana

the project have more chains as well for transaction

https://github.com/WalletConnect/web-examples/blob/main/dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx

const solanaRpc = {
    testSignTransaction: _createJsonRpcRequestHandler(
      async (
        chainId: string,
        address: string
      ): Promise<IFormattedRpcResponse> => {
        if (!solanaPublicKeys) {
          throw new Error("Could not find Solana PublicKeys.");
        }

        const senderPublicKey = solanaPublicKeys[address];

        // rpc.walletconnect.com doesn't support solana testnet yet
        const connection = new Connection(
          isTestnet ? clusterApiUrl("testnet") : getProviderUrl(chainId)
        );

        // Using deprecated `getRecentBlockhash` over `getLatestBlockhash` here, since `mainnet-beta`
        // cluster only seems to support `connection.getRecentBlockhash` currently.
        const { blockhash } = await connection.getRecentBlockhash();

        const transaction = new SolanaTransaction({
          feePayer: senderPublicKey,
          recentBlockhash: blockhash,
        }).add(
          SystemProgram.transfer({
            fromPubkey: senderPublicKey,
            toPubkey: Keypair.generate().publicKey,
            lamports: 1,
          })
        );

        try {
          const result = await client!.request<{ signature: string }>({
            chainId,
            topic: session!.topic,
            request: {
              method: DEFAULT_SOLANA_METHODS.SOL_SIGN_TRANSACTION,
              params: {
                feePayer: transaction.feePayer!.toBase58(),
                recentBlockhash: transaction.recentBlockhash,
                instructions: transaction.instructions.map((i) => ({
                  programId: i.programId.toBase58(),
                  data: Array.from(i.data),
                  keys: i.keys.map((k) => ({
                    isSigner: k.isSigner,
                    isWritable: k.isWritable,
                    pubkey: k.pubkey.toBase58(),
                  })),
                })),
              },
            },
          });

          // We only need `Buffer.from` here to satisfy the `Buffer` param type for `addSignature`.
          // The resulting `UInt8Array` is equivalent to just `bs58.decode(...)`.
          transaction.addSignature(
            senderPublicKey,
            Buffer.from(bs58.decode(result.signature))
          );

          const valid = transaction.verifySignatures();

          return {
            method: DEFAULT_SOLANA_METHODS.SOL_SIGN_TRANSACTION,
            address,
            valid,
            result: result.signature,
          };
        } catch (error: any) {
          throw new Error(error);
        }
      }
    ),
    testSignMessage: _createJsonRpcRequestHandler(
      async (
        chainId: string,
        address: string
      ): Promise<IFormattedRpcResponse> => {
        if (!solanaPublicKeys) {
          throw new Error("Could not find Solana PublicKeys.");
        }

        const senderPublicKey = solanaPublicKeys[address];

        // Encode message to `UInt8Array` first via `TextEncoder` so we can pass it to `bs58.encode`.
        const message = bs58.encode(
          new TextEncoder().encode(
            `This is an example message to be signed - ${Date.now()}`
          )
        );

        try {
          const result = await client!.request<{ signature: string }>({
            chainId,
            topic: session!.topic,
            request: {
              method: DEFAULT_SOLANA_METHODS.SOL_SIGN_MESSAGE,
              params: {
                pubkey: senderPublicKey.toBase58(),
                message,
              },
            },
          });

          const valid = verifyMessageSignature(
            senderPublicKey.toBase58(),
            result.signature,
            message
          );

          return {
            method: DEFAULT_SOLANA_METHODS.SOL_SIGN_MESSAGE,
            address,
            valid,
            result: result.signature,
          };
        } catch (error: any) {
          throw new Error(error);
        }
      }
    ),
  };

AmjadKhan2k18 avatar Aug 23 '23 08:08 AmjadKhan2k18

@quetool any plan to add example of making transaction with Solana/Tron/Polkadot blockchains?

AmjadKhan2k18 avatar Dec 12 '23 15:12 AmjadKhan2k18