anza-xyz/wallet-adapter

Detailed error messages on transaction sending

phoenixVS opened this issue · 2 comments

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

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.

@phoenixVS @mcintyre94 Any idea of were the Unexpected error is coming from ? Using the provider like phantom which is directly injected in the window without the walletAdapter, I have well defined error from the wallet. But when using the library, I always have

Error: Unexpected error
    at Pi.<anonymous> (<anonymous>:3:240911)
    at Generator.next (<anonymous>)
    at s (<anonymous>:1:1456)