Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The returned value of .request(...) method at the providers does not comply with EIP-1193 #6345

Closed
Muhammad-Altabba opened this issue Aug 10, 2023 · 1 comment · Fixed by #6407
Assignees
Labels

Comments

@Muhammad-Altabba
Copy link
Contributor

Expected behavior

The .request(...) method should return the result of the response, not the full response.

If resolved, the Promise MUST resolve with a result per the RPC method's specification. The Promise MUST NOT resolve with any RPC protocol-specific response objects, unless the RPC method's return type is so defined.
Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md

And this is how it is implemented for example by MetaMask as in https://docs.metamask.io/guide/ethereum-provider.html#methods:

const chainId = await ethereum.request({ method: 'eth_chainId' });

Actual behavior

The returned value is a response object like:

{
    jsonrpc: '2.0',
    result: []
}

And this caused an issue for example at Ganache repo when using the new provider from version 4.x with the pice of code: https://github.com/trufflesuite/truffle/blob/develop/packages/encoder/lib/adapter.ts#L150

Steps to reproduce the behavior

const { Web3 } = require('web3');

// Set up a connection to the Ethereum network
const url = 'http://127.0.0.1:7545/';
const provider = new Web3.providers.HttpProvider(url, { keepAlive: false });

async function run() {
    try {
        const response = await provider.request({
            method: 'eth_getLogs',
            params: [ { fromBlock: 5, toBlock: NaN, address: undefined } ]
          });

        // This currently logs: { jsonrpc: '2.0', result: [] }
        //  But it should log: []
        console.log('the response should be the result:', response)

    } catch (error) {
        console.error(error);
    }
}

run();

Environment

web3.js v4.0.3

Hint

If you face this issue, you can work around it by simply accessing response.result.

@Muhammad-Altabba
Copy link
Contributor Author

As discussed with @jdevcs, to avoid introducing a breaking change and avoid the need to pump the major version, we will keep the current behavior and document it.

However, this issue will be added to the 5.x To-do list. So, in version 5.x, it will be according to the EIP-1193.

@Muhammad-Altabba Muhammad-Altabba self-assigned this Sep 5, 2023
@Muhammad-Altabba Muhammad-Altabba linked a pull request Sep 6, 2023 that will close this issue
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant