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.61k stars 964 forks source link

Detailed error messages on transaction sending #985

Closed phoenixVS closed 4 months ago

phoenixVS commented 5 months 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 4 months 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.

LatentDream commented 4 months ago

@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)