solana_signTransaction error Unknown method(s) requested)
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/
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 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);
}
}
),
};
@quetool any plan to add example of making transaction with Solana/Tron/Polkadot blockchains?