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.44k stars 906 forks source link

Detailed error messages on transaction sending #985

Closed phoenixVS closed 3 days ago

phoenixVS commented 2 weeks ago

When using Phantom wallet adapter (or any other perhaps) and executing sendTransaction() with an error, the only info it provides is "Unexpected error" text.

Probably this error should be more descriptive, some RPC response with error code, something like this:

{
    "jsonrpc": "2.0",
    "error": {
        "code": -32002,
        "message": "Transaction simulation failed: Error processing Instruction 0: custom program error: 0x65",
        "data": {
            "accounts": null,
            "err": {
                "InstructionError": [
                    0,
                    {
                        "Custom": 101
                    }
                ]
            },
            "innerInstructions": null,
            "logs": [
                "Program DuHyR5VBu2hUdptTYiqaoSRAErDkYCuw8Yjxhmpj8rmB invoke [1]",
                "Program DuHyR5VBu2hUdptTYiqaoSRAErDkYCuw8Yjxhmpj8rmB consumed 109 of 200000 compute units",
                "Program DuHyR5VBu2hUdptTYiqaoSRAErDkYCuw8Yjxhmpj8rmB failed: custom program error: 0x65"
            ],
            "returnData": null,
            "unitsConsumed": 109
        }
    },
    "id": 1267
}

It also would have a great boost for WalletConnect's Web3Modal implementation developer experience

Additional context image

mcintyre94 commented 3 days ago

I'm going to close this because error messages come directly from the wallet and this repo can't do what you're asking. It's up to wallets to determine the error returned here.

Eg here you can see the Phantom adapter just wraps/throws whatever errors it catches from the Phantom wallet: https://github.com/anza-xyz/wallet-adapter/blob/689a3d1faf491aa83b47faef179ba8e90704d3f5/packages/wallets/phantom/src/adapter.ts#L217C1-L224C10

The wrapper around wallet-standard works similarly.

This repo also doesn't include the phrase "Unexpected error" so that's not something we can control here.