coinbase / coinbase-wallet-sdk

An open protocol that lets users connect their mobile wallets to your DApp
https://coinbase.github.io/coinbase-wallet-sdk/
MIT License
1.4k stars 522 forks source link

Bug: Error in Coinbase Wallet SDK Documentation for Smart Wallet Creation #1254

Closed sflanary97 closed 1 month ago

sflanary97 commented 2 months ago

Describe the bug

The documentation on the README here: https://github.com/coinbase/coinbase-wallet-sdk

Steps

Following documentation for Wallet SDK Version 4.0.0-rc on README, or Coinbase Smart Wallet Docs:

  1. Install @coinbase/wallet-sdk version 4.0.0-rc.1
  2. Initialize SDK:
    const sdk = new CoinbaseWalletSDK({
    appName: 'SDK Playground',
    });
  3. Initialize Provider:
    const provider = sdk.makeWeb3Provider();
  4. Request accounts:
    const addresses = provider.request('eth_requestAccounts');
  5. View error:
    ERROR
    Expected a single, non-array, object argument.
    at getEthJsonRpcError
    at Object.invalidRequest
    at checkErrorForInvalidRequestArgs
    at CoinbaseWalletProvider.request

In my case, after inspecting the util.js code for the CoinbaseWalletProvider.request's checkErrorForInvalidRequestArgs, it seems to be failing from this line:

/**
 * Validates the arguments for an invalid request and returns an error if any validation fails.
 * Valid request args are defined here: https://eips.ethereum.org/EIPS/eip-1193#request
 * @param args The request arguments to validate.
 * @returns An error object if the arguments are invalid, otherwise undefined.
 */
function checkErrorForInvalidRequestArgs(args) {
    if (!args || typeof args !== 'object' || Array.isArray(args)) {
        return error_1.standardErrors.rpc.invalidRequest({
            message: 'Expected a single, non-array, object argument.',
            data: args,
        });
    }
    ...
}

The documentation in this README as well as CoinBase Smart Wallet Docs pass in a single string argument to provider.request as 'eth_requestAccounts' but following the EIP-1193 specs, "The Provider MUST identify the requested RPC method by the value of RequestArguments.method."

To properly request accounts and view the Coinbase Wallet pop up, the documentation should be updated to provider.request({ method: 'eth_requestAccounts' }) instead of provider.request('eth_requestAccounts'). This update resolves the Expected a single, non-array, object argument

Expected behavior

Coinbase Smart Wallet should open after following README docs.

Version

4.0.0-rc.1

Additional info

Version from documentation

Screenshot 2024-04-30 at 8 40 44 PM

Produces this error:

Screenshot 2024-04-30 at 8 40 44 PM

Proposed Fix: const addresses = provider.request({ method: 'eth_requestAccounts' })

Produces expected wallet pop up:

Screenshot 2024-04-30 at 8 43 04 PM

Desktop

Browser - [tested on Brave, Chrome, Safari]

Smartphone

No response

Josh350Hops commented 2 months ago

Hey From Joshua

jakzaizzat commented 2 months ago

@sflanary97 Try to pass the object inside the request function

let response: string[] = await provider.request({
  method: 'eth_requestAccounts',
 })
nateReiners commented 1 month ago

Hi @sflanary97 thanks for catching this. This was a typo but has since been addressed. Also, we have new and improved docs here: https://www.smartwallet.dev/sdk/makeWeb3Provider#usage